Search in sources :

Example 1 with HibernatePersistenceProvider

use of org.hibernate.jpa.HibernatePersistenceProvider in project hibernate-orm by hibernate.

the class OrmVersionTest method testInvalidOrm1.

@Test
public void testInvalidOrm1() {
    PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl("invalid-orm1-test", "1.0").addMappingFileName("org/hibernate/jpa/test/jee/invalid-orm-1.xml");
    HibernatePersistenceProvider hp = new HibernatePersistenceProvider();
    EntityManagerFactory emf = null;
    try {
        emf = hp.createContainerEntityManagerFactory(pui, Collections.EMPTY_MAP);
        Assert.fail("expecting 'invalid content' error");
    } catch (InvalidMappingException | AnnotationException expected) {
    // expected condition
    } catch (PersistenceException expected) {
    // expected condition
    } finally {
        if (emf != null) {
            emf.close();
        }
    }
}
Also used : InvalidMappingException(org.hibernate.InvalidMappingException) EntityManagerFactory(javax.persistence.EntityManagerFactory) PersistenceException(javax.persistence.PersistenceException) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) AnnotationException(org.hibernate.AnnotationException) Test(org.junit.Test)

Example 2 with HibernatePersistenceProvider

use of org.hibernate.jpa.HibernatePersistenceProvider in project hibernate-orm by hibernate.

the class OrmVersionTest method testOrm1.

@Test
public void testOrm1() {
    PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl("orm1-test", "1.0").addMappingFileName("org/hibernate/jpa/test/jee/valid-orm-1.xml");
    HibernatePersistenceProvider hp = new HibernatePersistenceProvider();
    EntityManagerFactory emf = hp.createContainerEntityManagerFactory(pui, Collections.EMPTY_MAP);
    try {
        // exception if not entity
        emf.getMetamodel().entity(Lighter1.class);
    } finally {
        emf.close();
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) Test(org.junit.Test)

Example 3 with HibernatePersistenceProvider

use of org.hibernate.jpa.HibernatePersistenceProvider in project hibernate-orm by hibernate.

the class OrmVersionTest method testOrm2.

@Test
public void testOrm2() {
    PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl("orm2-test", "2.0").addMappingFileName("org/hibernate/jpa/test/jee/valid-orm-2.xml");
    HibernatePersistenceProvider hp = new HibernatePersistenceProvider();
    EntityManagerFactory emf = hp.createContainerEntityManagerFactory(pui, Collections.EMPTY_MAP);
    try {
        // exception if not entity
        emf.getMetamodel().entity(Lighter.class);
    } finally {
        emf.close();
    }
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) Test(org.junit.Test)

Example 4 with HibernatePersistenceProvider

use of org.hibernate.jpa.HibernatePersistenceProvider in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newJpaConfiguration.

@Override
public IConfiguration newJpaConfiguration(String entityResolver, String persistenceUnit, Map<Object, Object> overrides) {
    getUsageTracker().trackNewConfigurationEvent(HIBERNATE_VERSION);
    IConfiguration result = null;
    try {
        HibernatePersistenceProvider hibernatePersistenceProvider = new HibernatePersistenceProvider();
        Method getEntityManagerFactoryBuilderOrNull = hibernatePersistenceProvider.getClass().getDeclaredMethod("getEntityManagerFactoryBuilderOrNull", new Class[] { String.class, Map.class });
        getEntityManagerFactoryBuilderOrNull.setAccessible(true);
        Object entityManagerFactoryBuilder = getEntityManagerFactoryBuilderOrNull.invoke(hibernatePersistenceProvider, new Object[] { persistenceUnit, overrides });
        if (entityManagerFactoryBuilder == null) {
            throw new HibernateConsoleRuntimeException("Persistence unit not found: '" + persistenceUnit + "'.");
        }
        Method buildServiceRegistry = entityManagerFactoryBuilder.getClass().getMethod("buildServiceRegistry", new Class[0]);
        Object serviceRegistry = buildServiceRegistry.invoke(entityManagerFactoryBuilder, (Object[]) null);
        Class<?> serviceRegistryClass = StandardClassLoaderDelegateImpl.INSTANCE.classForName("org.hibernate.service.ServiceRegistry");
        Method buildHibernateConfiguration = entityManagerFactoryBuilder.getClass().getMethod("buildHibernateConfiguration", new Class[] { serviceRegistryClass });
        Configuration configuration = (Configuration) buildHibernateConfiguration.invoke(entityManagerFactoryBuilder, new Object[] { serviceRegistry });
        result = facadeFactory.createConfiguration(configuration);
    } catch (SecurityException | NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        throw new HibernateConsoleRuntimeException(e);
    }
    return result;
}
Also used : Configuration(org.hibernate.cfg.Configuration) JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 5 with HibernatePersistenceProvider

use of org.hibernate.jpa.HibernatePersistenceProvider in project hibernate-orm by hibernate.

the class NewBootProcessTest method basicNewBootProcessTest.

@Test
public void basicNewBootProcessTest() {
    Map settings = new HashMap();
    HibernatePersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
    final EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(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");
        }
    }, settings);
    emf.close();
}
Also used : JpaXsdVersionsTest(org.hibernate.test.jpa.xml.versions.JpaXsdVersionsTest) HashMap(java.util.HashMap) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernatePersistenceProvider(org.hibernate.jpa.HibernatePersistenceProvider) Map(java.util.Map) HashMap(java.util.HashMap) URL(java.net.URL) JpaXsdVersionsTest(org.hibernate.test.jpa.xml.versions.JpaXsdVersionsTest) Test(org.junit.Test)

Aggregations

HibernatePersistenceProvider (org.hibernate.jpa.HibernatePersistenceProvider)14 Test (org.junit.Test)10 EntityManagerFactory (javax.persistence.EntityManagerFactory)9 PersistenceException (javax.persistence.PersistenceException)3 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AnnotationException (org.hibernate.AnnotationException)2 InvalidMappingException (org.hibernate.InvalidMappingException)2 EntityManager (jakarta.persistence.EntityManager)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 SharedCacheMode (jakarta.persistence.SharedCacheMode)1 ValidationMode (jakarta.persistence.ValidationMode)1 ClassTransformer (jakarta.persistence.spi.ClassTransformer)1 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1 PersistenceUnitTransactionType (jakarta.persistence.spi.PersistenceUnitTransactionType)1 File (java.io.File)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1