我试图从JPA的EntityManager中获取Hibernate的SessionFactory,方法如下:
@PersistenceContext EntityManager manager; public SessionFactory getSessionFactory(){ sessionFactory = manager.unwrap(SessionFactory.class); }
但是它抛出了这个异常:
org.springframework.orm.jpa.JpaSystemException: Hibernate cannot unwrap interface org.hibernate.SessionFactory; nested exception is javax.persistence.PersistenceException: Hibernate cannot unwrap interface org.hibernate.SessionFactory at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:418) ... Caused by: javax.persistence.PersistenceException: Hibernate cannot unwrap interface org.hibernate.SessionFactory at org.hibernate.jpa.spi.AbstractEntityManagerImpl.unwrap(AbstractEntityManagerImpl.java:1489) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ...
这可能是什么原因?
提前致谢