![](/img/trans.png)
[英]How to get List<Object[]> from a query using Spring Jdbc
[英]how to get a result list from query using Object Query Language
我正在使用JPA / Hibernate,我想知道如何使用createquery檢索列表。 我努力了 :
EntityManagerFactory emf=Persistence.createEntityManagerFactory("JiraMapPUKPI");
EntityManager em= emf.createEntityManager();
EntityTransaction entr=em.getTransaction();
entr.begin();
Query multipleSelect =em.createQuery("select distinct k.kpiName FROM Kpi k ,ProfilUser p ,AssociationKpiProfil a WHERE p.profilUserId= :w and p.profilUserId= a.profilUser and a.kpi=k.kpiId " ).setParameter("w", userid);
但后來我不能使用:
List userList = (List)multipleSelect.getResultList();
因為multipleSelect不包含getResultList方法
我也嘗試過:
javax.persistence.Query multipleSelect= em.createQuery("select k.kpiName FROM Kpi k ,ProfilUser p ,AssociationKpiProfil a WHERE p.profilUserId= :w and p.profilUserId= a.profilUser and a.kpi=k.kpiId " );
multipleSelect.setParameter("w", userid);
List usrpro= multipleSelect.getResultList();
但是出現此錯誤:
EL Warning]: 2011-06-21 08:53:08.81--UnitOfWork(6850900)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND (t3.KPI_ID = t0.KPI_ID.t0.KPI_ID)) AND (t2.PROFIL_USER_ID = t3.PROFIL_ID)' at line 1
Error Code: 1064
Call: SELECT t0.KPI_NAME FROM association_kpi_profil t3, profil_user t2, profil_user , kpi t0 WHERE ((((t1.PROFIL_USER_ID = ?) AND (t1.PROFIL_USER_ID = )) AND (t3.KPI_ID = t0.KPI_ID.t0.KPI_ID)) AND (t2.PROFIL_USER_ID = t3.PROFIL_ID))
bind => [1 parameter bound]
Query: ReportQuery(referenceClass=Kpi sql="SELECT t0.KPI_NAME FROM association_kpi_profil t3, profil_user t2, profil_user t1, kpi t0 WHERE ((((t1.PROFIL_USER_ID = ?) AND (t1.PROFIL_USER_ID = )) AND (t3.KPI_ID = t0.KPI_ID.t0.KPI_ID)) AND (t2.PROFIL_USER_ID = t3.PROFIL_ID))")
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) AND (t3.KPI_ID = t0.KPI_ID.t0.KPI_ID)) AND (t2.PROFIL_USER_ID = t3.PROFIL_ID)' at line 1
Error Code: 1064
Call: SELECT t0.KPI_NAME FROM association_kpi_profil t3, profil_user t2, profil_user t1, kpi t0 WHERE ((((t1.PROFIL_USER_ID = ?) AND (t1.PROFIL_USER_ID = )) AND (t3.KPI_ID = t0.KPI_ID.t0.KPI_ID)) AND (t2.PROFIL_USER_ID = t3.PROFIL_ID))
bind => [1 parameter bound]
Query: ReportQuery(referenceClass=Kpi sql="SELECT t0.KPI_NAME FROM association_kpi_profil t3, profil_user t2, profil_user t1, kpi t0 WHERE ((((t1.PROFIL_USER_ID = ?) AND (t1.PROFIL_USER_ID = )) AND (t3.KPI_ID = t0.KPI_ID.t0.KPI_ID)) AND (t2.PROFIL_USER_ID = t3.PROFIL_ID))")
errrrrs
list kpiiiiiiiinull
請問我該怎么做? 謝謝
Hibernate生成的查詢不正確。 t1.PROFIL_USER_ID參數不存在。 嘗試檢查您的映射,並使用JOIN而不是equals。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.