Search in sources :

Example 11 with PersistenceUnitInfo

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

the class PersistenceXmlParsingTests method testMetaInfCase.

@Test
public void testMetaInfCase() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/orm/jpa/META-INF/persistence.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).isEqualTo(1);
    assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement");
    assertThat(info[0].getJarFileUrls().size()).isEqualTo(2);
    assertThat(info[0].getJarFileUrls().get(0)).isEqualTo(new ClassPathResource("order.jar").getURL());
    assertThat(info[0].getJarFileUrls().get(1)).isEqualTo(new ClassPathResource("order-supplemental.jar").getURL());
    assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 12 with PersistenceUnitInfo

use of jakarta.persistence.spi.PersistenceUnitInfo in project spring-boot by spring-projects.

the class AbstractJpaAutoConfigurationTests method customPersistenceUnitPostProcessors.

@Test
void customPersistenceUnitPostProcessors() {
    this.contextRunner.withUserConfiguration(TestConfigurationWithCustomPersistenceUnitPostProcessors.class).run((context) -> {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = context.getBean(LocalContainerEntityManagerFactoryBean.class);
        PersistenceUnitInfo persistenceUnitInfo = entityManagerFactoryBean.getPersistenceUnitInfo();
        assertThat(persistenceUnitInfo).isNotNull();
        assertThat(persistenceUnitInfo.getManagedClassNames()).contains("customized.attribute.converter.class.name");
    });
}
Also used : PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Test(org.junit.jupiter.api.Test)

Example 13 with PersistenceUnitInfo

use of jakarta.persistence.spi.PersistenceUnitInfo in project jOOQ by jOOQ.

the class AttributeConverterExtractor method initEntityManagerFactory.

private final EntityManagerFactory initEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    configuration.put("hibernate.integrator_provider", integratorProvider());
    configuration.put("hibernate.hbm2ddl.auto", "none");
    configuration.put(AvailableSettings.CONNECTION_PROVIDER, database.connectionProvider());
    PersistenceUnitInfoDescriptor descriptor = new PersistenceUnitInfoDescriptor(persistenceUnitInfo);
    return new EntityManagerFactoryBuilderImpl(descriptor, configuration).build();
}
Also used : PersistenceUnitInfoDescriptor(org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor) EntityManagerFactoryBuilderImpl(org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo)

Aggregations

PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)13 Test (org.junit.jupiter.api.Test)11 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)10 JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)9 ClassPathResource (org.springframework.core.io.ClassPathResource)4 HashMap (java.util.HashMap)2 DataSource (javax.sql.DataSource)2 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)2 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)1 PersistenceUnitInfoDescriptor (org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor)1 SimpleNamingContextBuilder (org.springframework.context.testfixture.jndi.SimpleNamingContextBuilder)1 MapDataSourceLookup (org.springframework.jdbc.datasource.lookup.MapDataSourceLookup)1 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)1