Hibernate

Hibernate Search method:

  一。 HQL

    from Cat  --- Cat是类名 

            from Cat as cat
              left join cat.kittens as kitten
              with kitten.bodyWeight
              > 10.0

    1.Join

   2. select 子句  

    select mate
      from Cat as cat
      inner join cat.mate as mate

       2.1查询语句可以返回多个对象和(或)属性,存放在 Object[] 队列中;

    2.2存放在一个 List 对象中;

    2.3类中;

                Family 有一个合适的构造函数 - 作为实际的类型安全的 Java 对象:
        select new Family(mother, mate, offspr)
          from DomesticCat as mother
          join mother.mate as mate
          left join mother.kittens as offspr

    2.4 Map 

      select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )  from Cat cat

         2.5. order by; group by

 

3. 批量的 UPDATE 和 DELETE

            HQL UPDATE 语句,默认不会影响更新实体的 version 或 the timestamp 属性值。这和 EJB3 规
    范是一致的。但是,通过使用 versioned update,你可以强制 Hibernate 正确的重置version 或者
    timestamp 属性值。这通过在 UPDATE 关键字后面增加 VERSIONED 关键字来实现的。
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    String hqlVersionedUpdate = "update versioned Customer set name = :newName where name = :oldName";
    int updatedEntities = s.createQuery( hqlUpdate )
                .setString( "newName", newName )
                .setString( "oldName", oldName )
                .executeUpdate();
        tx.commit();
    session.close();

    

二。 条件查询(Criteria Queries)

   2.1 限制结果集内容

      List cats = sess.createCriteria(Cat.class)
              .add( Restrictions.like("name", "Fritz%") )
              .add( Restrictions.between("weight", minWeight, maxWeight) )
              .list();

           Example example = Example.create(cat)
      .excludeZeroes() //exclude zero valued properties
      .excludeProperty("color") //exclude the property named "color"
      .ignoreCase() //perform case insensitive string comparisons
      .enableLike(); //use like for string comparisons
      List results = session.createCriteria(Cat.class)
      .add(example)
      .list();

 

 

 

 

 

转载于:https://www.cnblogs.com/tyler2000/archive/2010/12/29/Hibernate_Search.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值