hibernate 查询框架DetachedCriteria

DetachedCriteria
关联查询:
DetachedCriteria detachedCriteria = DetachedCriteria.forClass(User.Class)
detachedCriteria.createCriteria("集合属性").add(Restrictions.like("doorId",1));
或者
detachedCriteria.createAlias("集合属性","a").add(Restrictions.like("a.doorId",1));


Disjunction 或
Disjunction disjunction = Restrictions.disjunction();
Conjunction 与
Conjunction conjunction = Restrictions.conjunction();
都是Criterion的子类


Criteria是一个条件容器,Restrictions是一个工具类,提供了多个静态方法来创建Criterion的子类,并添加到Critera容器内。

工具类:Restrictions
eq:等于
allEq:多个键值对相等,使用Map
gt:大于
ge:大于等于
lt:小于
le:小于等于
between:区间
like:模糊
in:区间
and 与
or:或
sqlRestriction: SQL限定查询

sqlRestriction的例子
Restrictions.sqlRestriction("{alias}.name like (?)","aa",Hibernate.String)

String[] params={"aa","bb"}
Type[] types = {Hibernate.String, Hibernate.String};
Restrictions.sqlRestriction("{alias}.age between (?) and (?)",params,types)

你可能感兴趣的:(Hibernate,hibernate)