use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class InterceptorTest method testDeprecatedConfiguredInterceptor.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test deprecated Interceptor settings
@Test
public void testDeprecatedConfiguredInterceptor() {
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 javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class PersisterClassProviderTest method testPersisterClassProvider.
@Test
@SuppressWarnings("unchecked")
public void testPersisterClassProvider() {
Map settings = SettingsGenerator.generateSettings(PersisterClassResolverInitiator.IMPL_NAME, GoofyPersisterClassProvider.class, AvailableSettings.LOADED_CLASSES, Arrays.asList(Bell.class));
try {
EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
entityManagerFactory.close();
} catch (PersistenceException e) {
Assert.assertNotNull(e.getCause());
Assert.assertNotNull(e.getCause().getCause());
Assert.assertEquals(GoofyException.class, e.getCause().getCause().getClass());
}
}
use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class SessionFactoryObserverTest method testSessionFactoryObserverProperty.
@Test
public void testSessionFactoryObserverProperty() {
EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitInfoAdapter(), Collections.singletonMap(AvailableSettings.SESSION_FACTORY_OBSERVER, GoofySessionFactoryObserver.class.getName()));
try {
final EntityManagerFactory entityManagerFactory = builder.build();
entityManagerFactory.close();
Assert.fail("GoofyException should have been thrown");
} catch (GoofyException e) {
//success
}
}
use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class IdentifierGeneratorStrategyProviderTest method testIdentifierGeneratorStrategyProvider.
@Test
@SuppressWarnings("unchecked")
public void testIdentifierGeneratorStrategyProvider() {
Map settings = new HashMap();
settings.put(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER, FunkyIdentifierGeneratorProvider.class.getName());
settings.put(AvailableSettings.LOADED_CLASSES, Collections.singletonList(Cable.class));
final EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitInfoAdapter(), settings).build();
final EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
entityManager.persist(new Cable());
entityManager.flush();
Assert.fail("FunkyException should have been thrown when the id is generated");
} catch (FunkyException e) {
entityManager.close();
entityManagerFactory.close();
}
}
use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class OrmVersionTest method testInvalidOrm1.
@Test
public void testInvalidOrm1() {
PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl("invalid-orm1-test", "1.0").addMappingFileName("org/hibernate/jpa/test/jee/invalid-orm-1.xml");
HibernatePersistenceProvider hp = new HibernatePersistenceProvider();
EntityManagerFactory emf = null;
try {
emf = hp.createContainerEntityManagerFactory(pui, Collections.EMPTY_MAP);
Assert.fail("expecting 'invalid content' error");
} catch (InvalidMappingException | AnnotationException expected) {
// expected condition
} catch (PersistenceException expected) {
// expected condition
} finally {
if (emf != null) {
emf.close();
}
}
}
Aggregations