@Test public void testOrm21() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "orm2-test", "2.1" ) .addMappingFileName( "org/hibernate/test/jpa/xml/versions/valid-orm-2_1.xml" ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); EntityManagerFactory emf = hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); try { emf.getMetamodel().entity( Lighter.class ); // exception if not entity } finally { emf.close(); } }
@Test public void testOrm1() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "orm1-test", "1.0" ) .addMappingFileName( "org/hibernate/test/jpa/xml/versions/valid-orm-1_0.xml" ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); EntityManagerFactory emf = hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); try { emf.getMetamodel().entity( Lighter1.class ); // exception if not entity } finally { emf.close(); } }
@Test public void testOrm22() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "orm2-test", "2.2") .addMappingFileName( "org/hibernate/test/jpa/xml/versions/valid-orm-2_2.xml" ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); EntityManagerFactory emf = hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); try { emf.getMetamodel().entity( Lighter.class ); // exception if not entity } finally { emf.close(); } }
@Test public void testOrm20() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "orm2-test", "2.0" ) .addMappingFileName( "org/hibernate/test/jpa/xml/versions/valid-orm-2_0.xml" ); HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); EntityManagerFactory emf = hp.createContainerEntityManagerFactory( pui, Collections.EMPTY_MAP ); try { emf.getMetamodel().entity( Lighter.class ); // exception if not entity } finally { emf.close(); } }
@Test public void testInvalidOrm1() { PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl( "invalid-orm1-test", "1.0" ) .addMappingFileName( "org/hibernate/test/jpa/xml/versions/invalid-orm-1_0.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(); } } }
public static EntityManagerFactory createHibernateEntityManagerFactory(TreeLogger logger, GeneratorContext context) { Map<String, String> properties = new HashMap<String, String>(); properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); properties.put("javax.persistence.validation.mode", "none"); MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance(); List<String> managedTypeNames = new ArrayList<String>(); for (Class<?> entity : scanner.getTypesAnnotatedWith(Entity.class, RebindUtils.findTranslatablePackages(context))) { managedTypeNames.add(entity.getName()); } return new HibernatePersistenceProvider().createContainerEntityManagerFactory( new ErraiPersistenceUnitInfo(managedTypeNames), properties); }
@Override public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map) { final String persistenceProviderClassName = info.getPersistenceProviderClassName(); if ( persistenceProviderClassName == null || IMPLEMENTATION_NAME.equals( persistenceProviderClassName ) ) { Map<Object, Object> protectiveCopy = map != null ? new HashMap<Object, Object>( map ) : new HashMap<Object, Object>(); enforceOgmConfig( protectiveCopy ); //HEM only builds an EntityManagerFactory when HibernatePersistence.class.getName() is the PersistenceProvider //that's why we override it when //new DelegatorPersistenceUnitInfo(info) return delegate.createContainerEntityManagerFactory( new DelegatorPersistenceUnitInfo( info ), protectiveCopy ); } //not the right provider return null; }
@Before public void init() { PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName()); Map<String, Object> configuration = new HashMap<>(); Integrator integrator = integrator(); if (integrator != null) { configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator)); } emf = new HibernatePersistenceProvider().createContainerEntityManagerFactory( persistenceUnitInfo, configuration ); }
.create(); final HibernatePersistenceProvider hp = new HibernatePersistenceProvider(); factory = hp.createContainerEntityManagerFactory( unitInfo, new HashMap() );