Search in sources :

Example 36 with EntityManagerFactory

use of jakarta.persistence.EntityManagerFactory in project spring-framework by spring-projects.

the class SharedEntityManagerCreatorTests method deferredQueryWithResultList.

@Test
public void deferredQueryWithResultList() {
    EntityManagerFactory emf = mock(EntityManagerFactory.class);
    EntityManager targetEm = mock(EntityManager.class);
    Query query = mock(Query.class);
    given(emf.createEntityManager()).willReturn(targetEm);
    given(targetEm.createQuery("x")).willReturn(query);
    given(targetEm.isOpen()).willReturn(true);
    EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
    em.createQuery("x").getResultList();
    verify(query).getResultList();
    verify(targetEm).close();
}
Also used : EntityManager(jakarta.persistence.EntityManager) StoredProcedureQuery(jakarta.persistence.StoredProcedureQuery) Query(jakarta.persistence.Query) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) Test(org.junit.jupiter.api.Test)

Example 37 with EntityManagerFactory

use of jakarta.persistence.EntityManagerFactory in project jbosstools-hibernate by jbosstools.

the class JpaConfiguration method initialize.

void initialize() {
    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = HibernateToolsPersistenceProvider.createEntityManagerFactoryBuilder(persistenceUnit, getProperties());
    EntityManagerFactory entityManagerFactory = entityManagerFactoryBuilder.build();
    sessionFactory = (SessionFactory) entityManagerFactory;
    metadata = entityManagerFactoryBuilder.getMetadata();
    getProperties().putAll(entityManagerFactory.getProperties());
}
Also used : EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) EntityManagerFactory(jakarta.persistence.EntityManagerFactory)

Aggregations

EntityManagerFactory (jakarta.persistence.EntityManagerFactory)37 Test (org.junit.jupiter.api.Test)29 EntityManager (jakarta.persistence.EntityManager)25 StoredProcedureQuery (jakarta.persistence.StoredProcedureQuery)6 TransactionRequiredException (jakarta.persistence.TransactionRequiredException)6 Query (jakarta.persistence.Query)4 EntityTransaction (jakarta.persistence.EntityTransaction)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 EntityManagerHolder (org.springframework.orm.jpa.EntityManagerHolder)3 WebAsyncManager (org.springframework.web.context.request.async.WebAsyncManager)3 PersistenceException (jakarta.persistence.PersistenceException)2 AsyncEvent (jakarta.servlet.AsyncEvent)2 AsyncListener (jakarta.servlet.AsyncListener)2 FilterChain (jakarta.servlet.FilterChain)2 Callable (java.util.concurrent.Callable)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2