`
guozheng
  • 浏览: 70588 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

DetachedCriteria 用法 (来自网络)

阅读更多

如果每个美女都有自己的客户资源(不要想歪了!),那么需要查询拥有客户Gates的美女怎么办?

 
使用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,所以不会自动生成 
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics