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-從子句 –