query=entityManager.createQuery(" select a.birthDate from PersonalDetailsDomain a where a.empCode=(select b.empCode from User b where b.userId=?)");
query.setParameter(1,userId);
Date dob =(Date)query.getSingleResult();
EXCETION:休眠的异常当执行JPA子查询
java.lang.IllegalArgumentException异常:org.hibernate.QueryException:无法解析属性:的empCode:com.erp.hrms.User [选择.birthDate from com.erp.hrms.newjoinee.PersonalDetailsDomain a where a.empCode =(从com.erp.hrms.User b中选择b.empCode,其中b.userId =?)]
您的“用户”实体是否具有获取者和设置者的“empCode”属性? – mael
由于您正在编写纯SQL查询而不是HSQL,因此您必须提供表名称,而不是该单个表的POJO类名称 – 2013-07-25 06:47:04
您是否看过关于jpa&subquries的其他问题:http://stackoverflow.com/questions/13460235/jpa-2-criteria-using-in-and-subqueries http://stackoverflow.com/questions/11187188/jpa-criteria-query-with-subquery http://stackoverflow.com/questions/4662336/subquery -in-select-clause http://stackoverflow.com/questions/4483576/jpa-2-0-criteria-api-subqueries-in-expressions http://stackoverflow.com/questions/7269010/jpa-hibernate-subquery -in-从子句 –