我的工作從休眠/ OpenEJB的/ TomEE的應用遷移到Hibernate/JBoss和我有這樣的例外在運行時:爲什麼EntityManager的getDelegate()方法在Hibernate中不會返回EntityManagerImpl作爲底層對象?
java.lang.ClassCastException: org.hibernate.internal.SessionImpl cannot be cast to org.hibernate.ejb.EntityManagerImpl
雖然運行此代碼:
...
import javax.persistence.EntityManager;
...
@PersistenceContext(...)
protected EntityManager em;
...
EntityManagerImpl hibernateEntityManagerImpl = (EntityManagerImpl)em.getDelegate();
Session sess = hibernateEntityManagerImpl.getSession();
...
同代碼在TomEE中運行。我不知道爲什麼getDelegate()
方法不會將EntityManager作爲基礎對象返回。
NB:
- 應用程序已經使用Hibernate(有lawer版)之前,我只是將其遷移到JBoss;
- 我使用Hibernate的4.2.21.Final(同一版本的EntityManager);
- 的persistence.xml提供商
org.hibernate.ejb.HibernatePersistence
感謝您的幫助。
@NeilStockton:我糾正了我的言論。該應用程序已經與休眠,我正在遷移到JBoss。 –
僅供參考 - 檢查[JBoss Windup遷移工具](https://github.com/windup/windup/wiki)。 –
什麼版本的JBoss EAP? –