use of jakarta.persistence.Query in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method deferredQueryWithUpdate.
@Test
public void deferredQueryWithUpdate() {
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").executeUpdate();
verify(query).executeUpdate();
verify(targetEm).close();
}
use of jakarta.persistence.Query in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method deferredQueryWithSingleResult.
@Test
public void deferredQueryWithSingleResult() {
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").getSingleResult();
verify(query).getSingleResult();
verify(targetEm).close();
}
use of jakarta.persistence.Query in project spring-framework by spring-projects.
the class ApplicationManagedEntityManagerIntegrationTests method testEntityManagerProxyIsProxy.
@Test
@SuppressWarnings("unchecked")
public void testEntityManagerProxyIsProxy() {
EntityManager em = entityManagerFactory.createEntityManager();
assertThat(Proxy.isProxyClass(em.getClass())).isTrue();
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertThat(people).isNotNull();
assertThat(em.isOpen()).as("Should be open to start with").isTrue();
em.close();
assertThat(em.isOpen()).as("Close should work on application managed EM").isFalse();
}
use of jakarta.persistence.Query in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testQueryNoPersonsShared.
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersonsShared() {
Query q = this.sharedEntityManager.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList();
assertThat(people.size()).isEqualTo(0);
assertThatExceptionOfType(NoResultException.class).isThrownBy(q::getSingleResult);
}
use of jakarta.persistence.Query in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testQueryNoPersons.
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersons() {
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertThat(people.size()).isEqualTo(0);
assertThatExceptionOfType(NoResultException.class).isThrownBy(q::getSingleResult);
}
Aggregations