Java Code Examples for javax.persistence.spi.PersistenceProvider#createEntityManagerFactory()
The following examples show how to use
javax.persistence.spi.PersistenceProvider#createEntityManagerFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalEntityManagerFactoryBean.java From spring-analysis-note with MIT License | 6 votes |
/** * Initialize the EntityManagerFactory for the given configuration. * @throws javax.persistence.PersistenceException in case of JPA initialization errors */ @Override protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException { if (logger.isDebugEnabled()) { logger.debug("Building JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'"); } PersistenceProvider provider = getPersistenceProvider(); if (provider != null) { // Create EntityManagerFactory directly through PersistenceProvider. EntityManagerFactory emf = provider.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); if (emf == null) { throw new IllegalStateException( "PersistenceProvider [" + provider + "] did not return an EntityManagerFactory for name '" + getPersistenceUnitName() + "'"); } return emf; } else { // Let JPA perform its standard PersistenceProvider autodetection. return Persistence.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); } }
Example 2
Source File: LocalEntityManagerFactoryBean.java From java-technology-stack with MIT License | 6 votes |
/** * Initialize the EntityManagerFactory for the given configuration. * @throws javax.persistence.PersistenceException in case of JPA initialization errors */ @Override protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException { if (logger.isDebugEnabled()) { logger.debug("Building JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'"); } PersistenceProvider provider = getPersistenceProvider(); if (provider != null) { // Create EntityManagerFactory directly through PersistenceProvider. EntityManagerFactory emf = provider.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); if (emf == null) { throw new IllegalStateException( "PersistenceProvider [" + provider + "] did not return an EntityManagerFactory for name '" + getPersistenceUnitName() + "'"); } return emf; } else { // Let JPA perform its standard PersistenceProvider autodetection. return Persistence.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); } }
Example 3
Source File: LocalEntityManagerFactoryBean.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Initialize the EntityManagerFactory for the given configuration. * @throws javax.persistence.PersistenceException in case of JPA initialization errors */ @Override protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException { if (logger.isInfoEnabled()) { logger.info("Building JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'"); } PersistenceProvider provider = getPersistenceProvider(); if (provider != null) { // Create EntityManagerFactory directly through PersistenceProvider. EntityManagerFactory emf = provider.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); if (emf == null) { throw new IllegalStateException( "PersistenceProvider [" + provider + "] did not return an EntityManagerFactory for name '" + getPersistenceUnitName() + "'"); } return emf; } else { // Let JPA perform its standard PersistenceProvider autodetection. return Persistence.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); } }
Example 4
Source File: Persistence.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Create and return an EntityManagerFactory for the named persistence unit * using the given properties. * * @param persistenceUnitName * the name of the persistence unit * @param properties * Additional properties to use when creating the factory. * These properties may include properties to control * schema generation. The values of these properties override * any values that may have been configured elsewhere. * @return the factory that creates EntityManagers configured according to * the specified persistence unit. */ public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) { EntityManagerFactory emf = null; PersistenceProviderResolver resolver = PersistenceProviderResolverHolder.getPersistenceProviderResolver(); List<PersistenceProvider> providers = resolver.getPersistenceProviders(); for (PersistenceProvider provider : providers) { emf = provider.createEntityManagerFactory(persistenceUnitName, properties); if (emf != null) { break; } } if (emf == null) { throw new PersistenceException("No Persistence provider for EntityManager named " + persistenceUnitName); } return emf; }
Example 5
Source File: LocalEntityManagerFactoryBean.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Initialize the EntityManagerFactory for the given configuration. * @throws javax.persistence.PersistenceException in case of JPA initialization errors */ @Override protected EntityManagerFactory createNativeEntityManagerFactory() throws PersistenceException { if (logger.isInfoEnabled()) { logger.info("Building JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName() + "'"); } PersistenceProvider provider = getPersistenceProvider(); if (provider != null) { // Create EntityManagerFactory directly through PersistenceProvider. EntityManagerFactory emf = provider.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); if (emf == null) { throw new IllegalStateException( "PersistenceProvider [" + provider + "] did not return an EntityManagerFactory for name '" + getPersistenceUnitName() + "'"); } return emf; } else { // Let JPA perform its standard PersistenceProvider autodetection. return Persistence.createEntityManagerFactory(getPersistenceUnitName(), getJpaPropertyMap()); } }
Example 6
Source File: JpaPersistence.java From javamelody with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public EntityManagerFactory createEntityManagerFactory(final String unit, final Map map) { initJpaCounter(); final PersistenceProvider persistenceProvider = findDelegate(map); final ClassLoader tccl = tccl(); final ClassLoader hack = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // pour findbugs /** {@inheritDoc} */ @Override public ClassLoader run() { return new JpaOverridePersistenceXmlClassLoader(tccl, persistenceProvider.getClass().getName()); } }); Thread.currentThread().setContextClassLoader(hack); try { final Map overridenMap = new HashMap(); if (map != null) { overridenMap.putAll(map); } // #869 No Persistence provider for EntityManager, with Hibernate 5.4 & JPA // (when JpaOverridePersistenceXmlClassLoader is not enough) overridenMap.put(JPA_PERSISTENCE_PROVIDER, persistenceProvider.getClass().getName()); final EntityManagerFactory entityManagerFactory = persistenceProvider .createEntityManagerFactory(unit, overridenMap); if (entityManagerFactory == null) { return null; } return JpaWrapper.createEntityManagerFactoryProxy(entityManagerFactory); } finally { Thread.currentThread().setContextClassLoader(tccl); } }
Example 7
Source File: HibernateUtil.java From hibernate-demos with Apache License 2.0 | 5 votes |
private EntityManagerFactory getEntityManagerFactory() { if ( emf == null ) { Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class ); // Could get this by wiring up OsgiTestBundleActivator as well. BundleContext context = thisBundle.getBundleContext(); ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() ); PersistenceProvider persistenceProvider = (PersistenceProvider) context.getService( serviceReference ); emf = persistenceProvider.createEntityManagerFactory( "unmanaged-jpa", null ); } return emf; }