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();
}
}
}
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();
}
}
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();
}
}
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;
}
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();
}
Aggregations