求助大神,关于ssh多表查询的问题

一个需求,需要查询A表的一个数据,另有一个B表(A的子表),查询条件是A表B表,用的ssh,SQL语句附上 (select r.recordsid from record r left join record_config rc on r.record_id=rc.record_ID where r.srcpath="d://movie" and rc.quality=1),因为之前一直用的mybatis,所以hibernate的不怎么会用(java代码)

sql.append(" (select r.recordsid from record r left join record_config rc on r.record_id=rc.record_ID where r.srcpath="d://movie" and rc.quality=1) ");

http://www.w3school.com.cn/sql/sql_syntax.asp

没有什么是百度决绝不了的

额.我想问下接口怎么写

B表的 条件不能写在where里,否则左连接不起作用

建议你配置 hibernate的 一对多 多对关系 查一边两边都出来了

sql.append(" (select r.recordsid from record r left join record_config rc on r.record_id=rc.record_ID where r.srcpath="d://movie" and rc.quality=1) ");差不多吧

String hql =" from record r where r.srcpath="d://movie" and r.record_id in (select record_ID from record_config where quality=1)" 这么写就可以

String hql =" from record r where r.srcpath="d://movie" and r.record_id in (select record_ID from record_config where quality=1)" 这么写就可以

String hql =" from record r where r.srcpath="d://movie" and r.record_id in (select record_ID from record_config where quality=1)

我把代码贴一下吧
图片说明
图片说明
图片说明
图片说明
实体在hibernate.cfg.xml注入了,但是service和dao没有在applicationContext里面引入,因为没有找到,写的demo报空指针,不知道是不是这个原因,因为很久没写过了

String hql =" from record r where r.srcpath="d://movie" and r.record_id in (select record_ID from record_config where quality=1)"

sqlcmd =" from record r where r.srcpath="d://movie" and r.record_id in (select record_ID from record_config where quality=1)

sql.append(" (select r.recordsid from record r left join record_config rc on r.record_id=rc.record_ID where r.srcpath="d://movie" and rc.quality=1) ")
嗯嗯,这样是可以的,

hibernate中有多种方式 原生的hql 也有triteria查询 其实hibernate中也支持原来的sql语句的
这个是 hql语句

String hql="select j from Jd j where j.qx.id=1";//Jd 是街道的意思 街道有id name qx 区县的id from后面跟着的是类 名 要特别注意

Query q=session.createQuery(hql);
List jf=q.list();
for (Jd jd : jf) {
System.out.println(jd.getQx().getId());
}
sql 语句是
SQLQuery q=session.createSQLQuery("select id,name from jd");
List jd=q.list(); //返回的不是对象类型哦 是object数组 0代表id 1代表name
for (Object[] item : jd) {
System.out.println(item[0]+"-"+item[1]);
}