来源: [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]