use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class InterceptorTest method testOnLoadCallInInterceptor.
@Test
public void testOnLoadCallInInterceptor() {
Map settings = basicSettings();
settings.put(AvailableSettings.INTERCEPTOR, new ExceptionInterceptor(true));
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName("Laptop");
em.getTransaction().begin();
em.persist(i);
em.flush();
em.clear();
try {
em.find(Item.class, i.getName());
fail("No interceptor");
} catch (IllegalStateException e) {
assertEquals(ExceptionInterceptor.EXCEPTION_MESSAGE, e.getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class InterceptorTest method testConfiguredSessionInterceptor.
@Test
public void testConfiguredSessionInterceptor() {
Map settings = basicSettings();
settings.put(org.hibernate.cfg.AvailableSettings.SESSION_SCOPED_INTERCEPTOR, LocalExceptionInterceptor.class.getName());
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName("Laptop");
try {
em.getTransaction().begin();
em.persist(i);
em.getTransaction().commit();
fail("No interceptor");
} catch (IllegalStateException e) {
assertEquals(LocalExceptionInterceptor.LOCAL_EXCEPTION_MESSAGE, e.getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class InterceptorTest method testEmptyCreateEntityManagerFactoryAndPropertyUse.
@Test
public void testEmptyCreateEntityManagerFactoryAndPropertyUse() {
Map settings = basicSettings();
settings.put(AvailableSettings.INTERCEPTOR, ExceptionInterceptor.class.getName());
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName("Laptop");
try {
em.getTransaction().begin();
em.persist(i);
em.getTransaction().commit();
fail("No interceptor");
} catch (IllegalStateException e) {
assertEquals(ExceptionInterceptor.EXCEPTION_MESSAGE, e.getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class InterceptorTest method testDeprecatedConfiguredSessionInterceptor.
@Test
public void testDeprecatedConfiguredSessionInterceptor() {
Map settings = basicSettings();
settings.put(AvailableSettings.SESSION_INTERCEPTOR, LocalExceptionInterceptor.class.getName());
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
EntityManager em = emf.createEntityManager();
Item i = new Item();
i.setName("Laptop");
try {
em.getTransaction().begin();
em.persist(i);
em.getTransaction().commit();
fail("No interceptor");
} catch (IllegalStateException e) {
assertEquals(LocalExceptionInterceptor.LOCAL_EXCEPTION_MESSAGE, e.getMessage());
} finally {
if (em.getTransaction() != null && em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
emf.close();
}
}
use of org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.
the class MappedSuperclassType2Test method testMappedSuperclassAccessNoEntity.
@Test
@TestForIssue(jiraKey = "HHH-8534")
@FailureExpected(jiraKey = "HHH-8534")
public void testMappedSuperclassAccessNoEntity() {
// stupid? yes. tck does it? yes.
final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {
@Override
public List<String> getManagedClassNames() {
// pass in a MappedSuperclass that is not used in any entity hierarchy
return Arrays.asList(SomeMappedSuperclass.class.getName());
}
};
final Map settings = new HashMap();
settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
try {
ManagedType<SomeMappedSuperclass> type = emf.getMetamodel().managedType(SomeMappedSuperclass.class);
// the issue was in regards to throwing an exception, but also check for nullness
assertNotNull(type);
} finally {
emf.close();
}
}
Aggregations