|
|
|
@ -16,10 +16,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.orm.jpa.hibernate; |
|
|
|
package org.springframework.orm.jpa.hibernate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager; |
|
|
|
|
|
|
|
|
|
|
|
import org.hibernate.Session; |
|
|
|
import org.hibernate.Session; |
|
|
|
import org.hibernate.SessionFactory; |
|
|
|
import org.hibernate.SessionFactory; |
|
|
|
|
|
|
|
import org.hibernate.jpa.HibernateEntityManager; |
|
|
|
|
|
|
|
import org.hibernate.jpa.HibernateEntityManagerFactory; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
|
|
|
|
import org.springframework.aop.target.SingletonTargetSource; |
|
|
|
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; |
|
|
|
import org.springframework.orm.jpa.AbstractContainerEntityManagerFactoryIntegrationTests; |
|
|
|
import org.springframework.orm.jpa.EntityManagerFactoryInfo; |
|
|
|
import org.springframework.orm.jpa.EntityManagerFactoryInfo; |
|
|
|
import org.springframework.orm.jpa.EntityManagerProxy; |
|
|
|
import org.springframework.orm.jpa.EntityManagerProxy; |
|
|
|
@ -32,6 +38,7 @@ import static org.junit.Assert.*; |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") |
|
|
|
public class HibernateEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests { |
|
|
|
public class HibernateEntityManagerFactoryIntegrationTests extends AbstractContainerEntityManagerFactoryIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -43,12 +50,25 @@ public class HibernateEntityManagerFactoryIntegrationTests extends AbstractConta |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() { |
|
|
|
public void testCanCastNativeEntityManagerFactoryToHibernateEntityManagerFactoryImpl() { |
|
|
|
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; |
|
|
|
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory; |
|
|
|
|
|
|
|
assertTrue(emfi.getNativeEntityManagerFactory() instanceof HibernateEntityManagerFactory); |
|
|
|
assertTrue(emfi.getNativeEntityManagerFactory() instanceof SessionFactory); // as of Hibernate 5.2
|
|
|
|
assertTrue(emfi.getNativeEntityManagerFactory() instanceof SessionFactory); // as of Hibernate 5.2
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCanCastSharedEntityManagerProxyToHibernateEntityManager() { |
|
|
|
public void testCanCastSharedEntityManagerProxyToHibernateEntityManager() { |
|
|
|
|
|
|
|
assertTrue(sharedEntityManager instanceof HibernateEntityManager); |
|
|
|
assertTrue(((EntityManagerProxy) sharedEntityManager).getTargetEntityManager() instanceof Session); // as of Hibernate 5.2
|
|
|
|
assertTrue(((EntityManagerProxy) sharedEntityManager).getTargetEntityManager() instanceof Session); // as of Hibernate 5.2
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testCanUnwrapAopProxy() { |
|
|
|
|
|
|
|
EntityManager em = entityManagerFactory.createEntityManager(); |
|
|
|
|
|
|
|
EntityManager proxy = ProxyFactory.getProxy(EntityManager.class, new SingletonTargetSource(em)); |
|
|
|
|
|
|
|
assertTrue(em instanceof HibernateEntityManager); |
|
|
|
|
|
|
|
assertFalse(proxy instanceof HibernateEntityManager); |
|
|
|
|
|
|
|
assertTrue(proxy.unwrap(HibernateEntityManager.class) instanceof HibernateEntityManager); |
|
|
|
|
|
|
|
assertSame(em, proxy.unwrap(HibernateEntityManager.class)); |
|
|
|
|
|
|
|
assertSame(em.getDelegate(), proxy.getDelegate()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|