use of javax.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method transactionRequiredExceptionOnFlush.
@Test(expected = TransactionRequiredException.class)
public void transactionRequiredExceptionOnFlush() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.flush();
}
use of javax.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method transactionRequiredExceptionOnPersist.
@Test(expected = TransactionRequiredException.class)
public void transactionRequiredExceptionOnPersist() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.persist(new Object());
}
use of javax.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method transactionRequiredExceptionOnMerge.
@Test(expected = TransactionRequiredException.class)
public void transactionRequiredExceptionOnMerge() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.merge(new Object());
}
use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class ListenerTest method testLoadListener.
@Test(expected = SecurityException.class)
public void testLoadListener() {
Serializable customerId = 1L;
doInJPA(this::entityManagerFactory, entityManager -> {
EntityManagerFactory entityManagerFactory = entityManagerFactory();
SessionFactoryImplementor sessionFactory = entityManagerFactory.unwrap(SessionFactoryImplementor.class);
sessionFactory.getServiceRegistry().getService(EventListenerRegistry.class).prependListeners(EventType.LOAD, new SecuredLoadEntityListener());
Customer customer = entityManager.find(Customer.class, customerId);
});
}
use of javax.persistence.EntityManagerFactory in project hibernate-orm by hibernate.
the class EntityManagerFactoryClosedTest method testWithTransactionalEnvironment.
/**
* Test that using a closed EntityManagerFactory throws an IllegalStateException
* Also ensure that HHH-8586 doesn't regress.
* @throws Exception
*/
@Test
public void testWithTransactionalEnvironment() throws Exception {
assertFalse(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertTrue(JtaStatusHelper.isActive(TestingJtaPlatformImpl.INSTANCE.getTransactionManager()));
EntityManagerFactory entityManagerFactory = entityManagerFactory();
// close the underlying entity manager factory
entityManagerFactory.close();
try {
entityManagerFactory.createEntityManager();
fail("expected IllegalStateException when calling emf.createEntityManager with closed emf");
} catch (IllegalStateException expected) {
// success
}
try {
entityManagerFactory.getCriteriaBuilder();
fail("expected IllegalStateException when calling emf.getCriteriaBuilder with closed emf");
} catch (IllegalStateException expected) {
// success
}
try {
entityManagerFactory.getCache();
fail("expected IllegalStateException when calling emf.getCache with closed emf");
} catch (IllegalStateException expected) {
// success
}
assertFalse(entityManagerFactory.isOpen());
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
}
Aggregations