Es gab ähnliche Fragen in der Vergangenheit, aber keine echte Lösung.java.lang.ClassCastException: org.springframework.orm.hibernate5.SessionHolder kann nicht in org.springframework.orm.jpa.EntityManagerHolder umgewandelt werden
Ich konvertiere eine Hibernate Web App, um JPA-fähig zu sein. Es gibt bisher nur 1 DAO-Klasse, und es gibt bereits den folgenden Fehler nach der Konvertierung in JPA.
Hinweis: Wir verwenden Spring-Boot nicht, daher gelten vorherige Antworten in unserem Fall nicht.
java.lang.ClassCastException: org.springframework.orm.hibernate5.SessionHolder cannot be cast to org.springframework.orm.jpa.EntityManagerHolder
at org.springframework.orm.jpa.EntityManagerFactoryUtils.doGetTransactionalEntityManager(EntityManagerFactoryUtils.java:221)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:255)
at com.sun.proxy.$Proxy42.createQuery(Unknown Source)
at gov.nih.nci.cbiit.scimgmt.idp.dao.LookupDao.findById(LookupDao.java:52)
at gov.nih.nci.cbiit.scimgmt.idp.dao.LookupDao$$FastClassBySpringCGLIB$$7b0b6cbb.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:651)
at gov.nih.nci.cbiit.scimgmt.idp.dao.LookupDao$$EnhancerBySpringCGLIB$$1cd8b9dd.findById(<generated>)
at gov.nih.nci.cbiit.scimgmt.idp.service.impl.LookupServiceImpl.findById(LookupServiceImpl.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Converted DAO-Klasse-PPV aktiviert ist, nur 1 Methode:
public class LookupDao {
private final Logger log = LogManager.getLogger(getClass());
@PersistenceContext
private EntityManager entityManager;
public LookupT findById(long id) throws Exception {
log.info("Entered: LookupDao.findById(), id = " + id);
// Pre-JPA (pre-conversion; note: commented out. No Hibernate Session conflicts)
// -------
/*
log.info("getting lookup id="+id);
return sessionFactory.getCurrentSession().get(LookupT.class, id);
*/
// New JPA Approach (converted)
// ----------------
CriteriaBuilder crbuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<LookupT> crquery = crbuilder.createQuery(LookupT.class);
Root<LookupT> root = crquery.from(LookupT.class);
crquery.where(
(crbuilder.equal(root.get("id"), id))
);
Query q = entityManager.createQuery(crquery);
return (LookupT)q.getSingleResult();
}
Bibliotheken:
- feder AOP-4.3.2.RELEASE.jar
- feder Bohnen -4.3.2.RELEASE.jar
- spring-context-4.3.2.RELEASE.jar
- Federkern-4.3.2.RELEASE.jar
- feder jdbc-4.3.2.RELEASE.jar
- Feder-web-4.3.2.RELEASE.jar
- Hibernate-commons-annotations- 5.0.1.Final.jar
- Hibernate-core-5.2.1.Final.jar
- hibernate-JPA-2,1-api-1.0.0.Final.jar
Gibt es noch etwas, das hilfreich sein könnte, um dies zu debuggen?
Ich habe bestätigt:
- Keine Vermischung zwischen Hibernate Session und EntityManager, nur 1 DAO mit 1 Verfahren die EntityManager verwenden, alles andere ist out kommentiert.
- Nicht
Vor Fragen zu diesem Thema Frühling-Boot mit: Spring 4 + Hibernate 5 = org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder