来源: [url]http://www.iteye.com/problems/11751[/url]
怎么用Hibernate写SQL里的in式的子查询
select * from tableA where tableA.Id in (select Id from tableA where tableA.name like "M%")
大家帮我看看用Hibernate里的DetachedCriteria和Subqueries等来把上面的SQL转为Hibernate的查询条件呢?
采纳的答案
2009-02-23 sophia_230 (初级程序员)
DetachedCriteria a_ids = DetachedCriteria.forClass(tableA.class, "inner")
.setProjection(Property.forName("inner.id")).add(( Property.forName("inner.name").like("M",MatchMode.START) ));
return super.getSession().createCriteria(tableA.class, "outer")
.add( Property.forName("id).in(a_ids)).list();
--------------------------------------------------------------------------------
来源: [url]http://www.iteye.com/problems/11751[/url]
怎么用Hibernate写SQL里的in式的子查询
select * from tableA where tableA.Id in (select Id from tableA where tableA.name like "M%")
大家帮我看看用Hibernate里的DetachedCriteria和Subqueries等来把上面的SQL转为Hibernate的查询条件呢?
采纳的答案
2009-02-23 sophia_230 (初级程序员)
DetachedCriteria a_ids = DetachedCriteria.forClass(tableA.class, "inner")
.setProjection(Property.forName("inner.id")).add(( Property.forName("inner.name").like("M",MatchMode.START) ));
return super.getSession().createCriteria(tableA.class, "outer")
.add( Property.forName("id).in(a_ids)).list();
--------------------------------------------------------------------------------
来源: [url]http://www.iteye.com/problems/11751[/url]
本文介绍如何使用Hibernate的DetachedCriteria和Subqueries实现SQL中的IN子查询。通过具体示例展示了如何将原生SQL转换为Hibernate查询条件。
3493

被折叠的 条评论
为什么被折叠?



