Я использую 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();
, поскольку множественный выбор не содержит метод 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
Пожалуйста, как я могу это сделать?
Спасибо