use of jakarta.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class LocalContainerEntityManagerFactoryBean method createNativeEntityManagerFactory.
@Override
protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException {
Assert.state(this.persistenceUnitInfo != null, "PersistenceUnitInfo not initialized");
PersistenceProvider provider = getPersistenceProvider();
if (provider == null) {
String providerClassName = this.persistenceUnitInfo.getPersistenceProviderClassName();
if (providerClassName == null) {
throw new IllegalArgumentException("No PersistenceProvider specified in EntityManagerFactory configuration, " + "and chosen PersistenceUnitInfo does not specify a provider class name either");
}
Class<?> providerClass = ClassUtils.resolveClassName(providerClassName, getBeanClassLoader());
provider = (PersistenceProvider) BeanUtils.instantiateClass(providerClass);
}
if (logger.isDebugEnabled()) {
logger.debug("Building JPA container EntityManagerFactory for persistence unit '" + this.persistenceUnitInfo.getPersistenceUnitName() + "'");
}
EntityManagerFactory emf = provider.createContainerEntityManagerFactory(this.persistenceUnitInfo, getJpaPropertyMap());
postProcessEntityManagerFactory(emf, this.persistenceUnitInfo);
return emf;
}
use of jakarta.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method deferredQueryWithResultStream.
@Test
public void deferredQueryWithResultStream() {
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").getResultStream();
verify(query).getResultStream();
verify(targetEm).close();
}
use of jakarta.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method transactionRequiredExceptionOnRefresh.
@Test
public void transactionRequiredExceptionOnRefresh() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
assertThatExceptionOfType(TransactionRequiredException.class).isThrownBy(() -> em.refresh(new Object()));
}
use of jakarta.persistence.EntityManagerFactory in project spring-framework by spring-projects.
the class SharedEntityManagerCreatorTests method proxyingWorksIfInfoReturnsNullEntityManagerInterface.
@Test
public void proxyingWorksIfInfoReturnsNullEntityManagerInterface() {
EntityManagerFactory emf = mock(EntityManagerFactory.class, withSettings().extraInterfaces(EntityManagerFactoryInfo.class));
// EntityManagerFactoryInfo.getEntityManagerInterface returns null
assertThat(SharedEntityManagerCreator.createSharedEntityManager(emf)).isNotNull();
}
Aggregations