关于hibernate的多表查询,懂的进来讲一下,我新手
有两张表
A表:id name age
B表:id sid(id外键)
我只想用B表的sid查询A表中的记录
我的hql该怎么写
Query q = s.createQuery(hql);
Iterator it =q.list().Iterator();
懂的讲讲下
谢谢
------解决方案--------------------String hql = "from A a where id= "+ sid;(单个sid)
String hql = "from A a where a.id in (select distinct b.sid from B b) ";(B表内所有存在的sid)
------解决方案--------------------1楼正解!
------解决方案--------------------String sql = " select (a.*) from A a ,B b where A.id = B.sid ";
Query query = session.createSQLQuery(sql, "a ",A.class);