Search in sources :

Example 6 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class MappingClassMoreThanOnceTest method testBootstrapWithClassMappedMOreThanOnce.

/**
 * Tests that an entity manager can be created when a class is mapped more than once.
 */
@Test
@TestForIssue(jiraKey = "HHH-8775")
public // @FailureExpected(jiraKey = "HHH-8775")
void testBootstrapWithClassMappedMOreThanOnce() {
    Map settings = new HashMap();
    settings.put(AvailableSettings.HBXML_FILES, "org/hibernate/jpa/test/callbacks/hbmxml/ClassMappedMoreThanOnce.hbm.xml");
    final EntityManagerFactoryBuilder builder = Bootstrap.getEntityManagerFactoryBuilder(new BaseEntityManagerFunctionalTestCase.TestingPersistenceUnitDescriptorImpl(getClass().getSimpleName()), settings);
    HibernateEntityManagerFactory emf = null;
    try {
        emf = builder.build().unwrap(HibernateEntityManagerFactory.class);
    } finally {
        if (emf != null) {
            try {
                emf.close();
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : BaseEntityManagerFunctionalTestCase(org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase) HashMap(java.util.HashMap) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) Map(java.util.Map) HashMap(java.util.HashMap) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 7 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class HibernatePersistenceProvider method generateSchema.

@Override
public void generateSchema(PersistenceUnitInfo info, Map map) {
    log.tracef("Starting generateSchema : PUI.name=%s", info.getPersistenceUnitName());
    final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilder(info, map);
    builder.generateSchema();
}
Also used : EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)

Example 8 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class JpaSchemaGeneratorTest method doTest.

@SuppressWarnings("unchecked")
private void doTest(Map settings) {
    // We want a fresh db after emf close
    // Unfortunately we have to use this dirty hack because the db seems not to be closed otherwise
    settings.put("hibernate.connection.url", "jdbc:h2:mem:db-schemagen" + schemagenNumber++ + ";MVCC=TRUE;LOCK_TIMEOUT=10000");
    EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder(buildPersistenceUnitDescriptor(), settings);
    EntityManagerFactory emf = emfb.build();
    try {
        EntityManager em = emf.createEntityManager();
        try {
            Assert.assertNotNull(em.find(Item.class, encodedName()));
        } finally {
            em.close();
        }
    } finally {
        emf.close();
        emfb.cancel();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)

Example 9 with EntityManagerFactoryBuilder

use of org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder in project hibernate-orm by hibernate.

the class ValidatorFactory2PhaseInjectionTest method testInjectionAvailabilityFromEmf.

@Test
public void testInjectionAvailabilityFromEmf() {
    EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder(new JpaXsdVersionsTest.PersistenceUnitInfoImpl("my-test") {

        @Override
        public URL getPersistenceUnitRootUrl() {
            // just get any known url...
            return HibernatePersistenceProvider.class.getResource("/org/hibernate/jpa/persistence_1_0.xsd");
        }
    }, Collections.emptyMap());
    emfb.withValidatorFactory(vf);
    EntityManagerFactory emf = emfb.build();
    try {
        assertSame(vf, emf.getProperties().get(AvailableSettings.VALIDATION_FACTORY));
    } finally {
        emf.close();
    }
}
Also used : JpaXsdVersionsTest(org.hibernate.test.jpa.xml.versions.JpaXsdVersionsTest) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder) URL(java.net.URL) JpaXsdVersionsTest(org.hibernate.test.jpa.xml.versions.JpaXsdVersionsTest) Test(org.junit.Test)

Aggregations

EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)9 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BaseEntityManagerFunctionalTestCase (org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase)2 PersistenceDescriptorFactory (com.robo4j.db.sql.jpa.PersistenceDescriptorFactory)1 URL (java.net.URL)1 EntityManager (javax.persistence.EntityManager)1 PersistenceUnitInfo (javax.persistence.spi.PersistenceUnitInfo)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 HibernateEntityManagerFactory (org.hibernate.jpa.HibernateEntityManagerFactory)1 HibernatePersistenceProvider (org.hibernate.jpa.HibernatePersistenceProvider)1 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)1 PersistenceUnitInfoDescriptor (org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor)1 PersistenceUnitDescriptor (org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor)1 PersistenceUnitInfoAdapter (org.hibernate.jpa.test.PersistenceUnitInfoAdapter)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 JpaXsdVersionsTest (org.hibernate.test.jpa.xml.versions.JpaXsdVersionsTest)1 TestForIssue (org.hibernate.testing.TestForIssue)1