hibernate两个表的联合查询 查询其中一个表

写法1 

@Override

public List<RevitAddIn> getMyDownLoadRevit(Long staffId) {

String hql = "select pc from RevitAddIn pc,RevitDownLoad rct where pc.id=rct.staffId and rct.staffId=:staffId";
return this.getCurrentSession().createQuery(hql).setLong("staffId", staffId).list();

}


写法2 利用sql

@Override
public List<Map<String, Object>> findGroupStaffList(String groupUuid) throws Exception {
SqlBuilder sql = new SqlBuilder();
sql.append("SELECT po.org_name AS poName,pos.org_staff_job AS posName,s.staff_name AS staffName,s.photo_path AS photoPath,");
sql.append("s.id AS staffId,pos.id AS posId,po.id AS poId");
sql.append("FROM project_group_staffs pgs INNER JOIN project_organization_staffs pos ON pgs.pos_id=pos.id");
sql.append("        INNER JOIN project_organizations po ON pos.project_organization_id=po.id");
sql.append("        INNER JOIN staffs s ON pgs.staff_id=s.id");
sql.append("WHERE pgs.group_uuid=:groupUuid");
return session().createSQLQuery(sql.toString()).setString("groupUuid", groupUuid)
.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
}



你可能感兴趣的:(hibernate两个表的联合查询 查询其中一个表)