我嘗試使用java和hibernate傳遞一個小應用程序,當我運行此應用程序的測試類時正如你看到的錯誤是階級MetierImplhibernate錯誤:java.lang.ClassCastException:org.hibernate.impl.QueryImpl不能轉換爲javax.persistence.Query
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: insert into REUNION (TITREREUNION, DATEREUNION) values (?, ?)
Hibernate: insert into REUNION (TITREREUNION, DATEREUNION) values (?, ?)
Hibernate: insert into REUNION (TITREREUNION, DATEREUNION) values (?, ?)
Exception in thread "main" java.lang.ClassCastException: org.hibernate.impl.QueryImpl cannot be cast to javax.persistence.Query
at metier.MetierImpl.getAllReunion(MetierImpl.java:62)
at Test.main(Test.java:21)
:收到此錯誤信息導致錯誤的方法是:
public Reunion getAllReunion(){
Session session =sessionFactory.getCurrentSession();
session.beginTransaction();
Query req=(Query) session.createQuery("select R from Reunion ");
List<Reunion> list = req.getResultList();
Reunion r=(Reunion) req.getResultList().get(0);
return r;
}
你不能只是刪除鑄造到(查詢)在線(查詢)session.createQuery(「選擇R留尼汪」); –
當我刪除鑄造查詢這是一個錯誤,它迫使我添加鑄造 –
,因爲你不使用正確的查詢類,你應該從休眠而不是javax.persistence.Query –