DetachedCriteria 用法

来源:互联网 发布:水牛城66 知乎 编辑:程序博客网 时间:2024/05/28 05:15
使用Criteria可以有两种方法:
 
1:
DetachedCriteria beautyCriteria = DetachedCriteria.forClass(Beauty.class).createCriteria("customers");
beautyCriteria.add(Restrictions.eq("name", "Gates")):
 
2:
DetachedCriteria beautyCriteria = DetachedCriteria.forClass(Beauty.class).createAlias("customers", "c");
beautyCriteria.add(Restrictions.eq("c.name", "Gates")):
 
接着有了新的要求,年纪太大的美女不要,还是查找拥有客户Gates的,条件如下:
DetachedCriteria beautyCriteria = DetachedCriteria.forClass(Beauty.class, "b").;
DetachedCriteria customerCriteria = beautyCriteria.createAlias("customers", c");
beautyCriteria.add(Restrictions.le("b.age", new Long(20))):
customerCriteria.add(Restrictions.eq("c.name", "Gates")):
 
----------------------------------------------------------------------------------------------
 
<prop key="hibernate.hbm2ddl.auto">update</prop>
 
其中update表示加载hibernate自动更新数据库结构,你也可以用create,但这样你数据库中的所有数据都会被清除,估计你现在写的是none,所以不会自动生成 
原创粉丝点击