如何在条件中转换hibernate sql查询:
String hql = "from OMRDetailsTable omrDetailsTable " +
"where omrDetailsTable.bar_code_no not in(" +
"select roll_no from RejectListTable rejectListTable where rejectListTable.rej_status='R') " +
"and omrDetailsTable.roll_no not in(" +
"select roll_no from RejectListTable rejectListTable where rejectListTable.rej_status='R') " +
"and omrDetailsTable.omr_error in('T','U') order by omrDetailsTable.roll_no";
我尝试过转换它但会抛出此异常:could not resolve property: parent of: com.templateproject.table.OMRDetailsTable
DetachedCriteria subCriteria = DetachedCriteria.forClass(RejectListTable.class);
subCriteria.add(Restrictions.eq("rej_status", 'R'));
subCriteria.setProjection(Projections.property("roll_no"));
subCriteria.setProjection(Projections.property("error_type"));
Criteria criteria = session.createCriteria(OMRDetailsTable.class);
criteria.add(Restrictions.eq("omr_error", 'T'));
criteria.add(Restrictions.eq("omr_error", 'U'));
criteria.add(Subqueries.propertyEq("parent", subCriteria));
我的错误是什么?
答案 0 :(得分:0)
您只需要一次投影
DetachedCriteria subCriteria = DetachedCriteria.forClass(RejectListTable.class);
subCriteria.add(Restrictions.eq("rej_status", 'R'));
subCriteria.setProjection(Projections.property("roll_no"));
并且,请Subqueries.notIn()
使用roll_no
(不是parent
)
Subqueries.notIn("roll_no", subCriteria)