Search in sources :

Example 1 with PersistenceUnitDescriptorAdapter

use of org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.

the class PersisterClassProviderTest method testPersisterClassProvider.

@Test
public void testPersisterClassProvider() {
    Map settings = SettingsGenerator.generateSettings(PersisterClassResolverInitiator.IMPL_NAME, GoofyPersisterClassProvider.class, AvailableSettings.LOADED_CLASSES, Arrays.asList(Bell.class));
    try {
        EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
        entityManagerFactory.close();
    } catch (PersistenceException e) {
        Assertions.assertNotNull(e.getCause());
        Assertions.assertNotNull(e.getCause().getCause());
        Assertions.assertEquals(GoofyException.class, e.getCause().getCause().getClass());
    }
}
Also used : EntityManagerFactory(jakarta.persistence.EntityManagerFactory) PersistenceException(jakarta.persistence.PersistenceException) PersistenceUnitDescriptorAdapter(org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with PersistenceUnitDescriptorAdapter

use of org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.

the class MappedSuperclassType2Test method testMappedSuperclassAccessNoEntity.

@Test
@TestForIssue(jiraKey = "HHH-8534")
@FailureExpected(jiraKey = "HHH-8534")
public void testMappedSuperclassAccessNoEntity() {
    // stupid? yes.  tck does it? yes.
    final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {

        @Override
        public List<String> getManagedClassNames() {
            // pass in a MappedSuperclass that is not used in any entity hierarchy
            return Arrays.asList(SomeMappedSuperclass.class.getName());
        }
    };
    final Map settings = new HashMap();
    settings.put(AvailableSettings.HBM2DDL_AUTO, "create-drop");
    EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
    try {
        ManagedType<SomeMappedSuperclass> type = emf.getMetamodel().managedType(SomeMappedSuperclass.class);
        // the issue was in regards to throwing an exception, but also check for nullness
        assertNotNull(type);
    } finally {
        emf.close();
    }
}
Also used : HashMap(java.util.HashMap) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) PersistenceUnitDescriptorAdapter(org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter) HashMap(java.util.HashMap) Map(java.util.Map) BaseUnitTest(org.hibernate.testing.orm.junit.BaseUnitTest) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with PersistenceUnitDescriptorAdapter

use of org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.

the class TransactionCommitFailureTest method setUp.

@BeforeEach
public void setUp() {
    // static variables need to be initialized before the EMF is set up, because they can be referenced during EMF setup via the connection provider.
    transactionFailureTrigger = new AtomicBoolean();
    connectionIsOpen = new AtomicBoolean();
    final Map settings = basicSettings();
    emf = Bootstrap.getEntityManagerFactoryBuilder(new PersistenceUnitDescriptorAdapter(), settings).build();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PersistenceUnitDescriptorAdapter(org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter) Map(java.util.Map) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with PersistenceUnitDescriptorAdapter

use of org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.

the class Hbm2ddlCreateOnlyTest method testColumnAnnotationWithExplicitReferenceToPrimaryTable.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@TestForIssue(jiraKey = "HHH-12955")
public void testColumnAnnotationWithExplicitReferenceToPrimaryTable() {
    final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() {

        @Override
        public List<String> getManagedClassNames() {
            return Arrays.asList(AnEntity.class.getName());
        }
    };
    final Map settings = new HashMap();
    settings.put(AvailableSettings.HBM2DDL_AUTO, "create-only");
    EntityManagerFactory emf = null;
    try {
        Triggerable triggerable = logInspection.watchForLogMessages("Unrecognized " + AvailableSettings.HBM2DDL_AUTO + " value");
        emf = Bootstrap.getEntityManagerFactoryBuilder(pu, settings).build();
        emf.createEntityManager();
        assertFalse(triggerable.wasTriggered());
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
}
Also used : HashMap(java.util.HashMap) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) Triggerable(org.hibernate.testing.logger.Triggerable) PersistenceUnitDescriptorAdapter(org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter) AnEntity(org.hibernate.orm.test.jpa.mapping.ColumnWithExplicitReferenceToPrimaryTableTest.AnEntity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with PersistenceUnitDescriptorAdapter

use of org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter in project hibernate-orm by hibernate.

the class JakartaSchemaToolingTests method buildSessionFactory.

private SessionFactoryImplementor buildSessionFactory(Object... settingPairs) {
    final Properties settings = CollectionHelper.toProperties(settingPairs);
    final PersistenceUnitDescriptorAdapter puDescriptor = new PersistenceUnitDescriptorAdapter() {

        @Override
        public Properties getProperties() {
            return settings;
        }

        @Override
        public List<String> getManagedClassNames() {
            return Collections.singletonList(SimpleEntity.class.getName());
        }
    };
    final EntityManagerFactoryBuilder emfBuilder = Bootstrap.getEntityManagerFactoryBuilder(puDescriptor, settings, (mergedSettings) -> mergedSettings.getConfigurationValues().clear());
    return emfBuilder.build().unwrap(SessionFactoryImplementor.class);
}
Also used : Properties(java.util.Properties) PersistenceUnitDescriptorAdapter(org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter) EntityManagerFactoryBuilder(org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)

Aggregations

PersistenceUnitDescriptorAdapter (org.hibernate.testing.orm.jpa.PersistenceUnitDescriptorAdapter)7 Map (java.util.Map)4 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 TestForIssue (org.hibernate.testing.TestForIssue)2 Test (org.junit.jupiter.api.Test)2 PersistenceException (jakarta.persistence.PersistenceException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EntityManagerFactoryBuilderImpl (org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl)1 EntityManagerFactoryBuilder (org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder)1 AnEntity (org.hibernate.orm.test.jpa.mapping.ColumnWithExplicitReferenceToPrimaryTableTest.AnEntity)1 Triggerable (org.hibernate.testing.logger.Triggerable)1 BaseUnitTest (org.hibernate.testing.orm.junit.BaseUnitTest)1 FailureExpected (org.hibernate.testing.orm.junit.FailureExpected)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1