本文整理匯總了Java中javax.persistence.spi.PersistenceProvider.createEntityManagerFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java PersistenceProvider.createEntityManagerFactory方法的具體用法?Java PersistenceProvider.createEntityManagerFactory怎麽用?Java PersistenceProvider.createEntityManagerFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.persistence.spi.PersistenceProvider
的用法示例。
在下文中一共展示了PersistenceProvider.createEntityManagerFactory方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createNativeEntityManagerFactory
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
/**
* 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());
}
}
示例2: createEntityManagerFactory
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
public static EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
EntityManagerFactory emf = null;
List<PersistenceProvider> providers = getProviders();
PersistenceProvider defaultProvider = null;
for (PersistenceProvider provider : providers) {
if (provider instanceof HibernatePersistence) {
defaultProvider = provider;
continue;
}
emf = provider.createEntityManagerFactory(persistenceUnitName, properties);
if (emf != null) {
break;
}
}
if (emf == null && defaultProvider != null)
emf = defaultProvider.createEntityManagerFactory( persistenceUnitName, properties );
if ( emf == null ) {
throw new PersistenceException( "No Persistence provider for EntityManager named " + persistenceUnitName );
}
return emf;
}
示例3: getEmf
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
public EntityManagerFactory getEmf()
{
Bundle thisBundle = FrameworkUtil.getBundle( EmfUtil.class );
BundleContext context = thisBundle.getBundleContext();
ServiceReference[] refs = null;
try
{
refs = context.getServiceReferences( EntityManagerFactory.class.getName(),
"(osgi.unit.name=pluginsPUnit)" );
}
catch ( Exception isEx )
{
throw new IllegalStateException( "Filter error", isEx );
}
if ( refs != null )
{
emf = ( EntityManagerFactory ) context.getService( refs[0] );
}
if ( emf == null )
{
ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() );
PersistenceProvider persistenceProvider = ( PersistenceProvider ) context.getService( serviceReference );
emf = persistenceProvider.createEntityManagerFactory( "pluginsPUnit", null );
}
return emf;
}
示例4: createEntityManagerFactory
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
@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 EntityManagerFactory entityManagerFactory = persistenceProvider
.createEntityManagerFactory(unit, map);
if (entityManagerFactory == null) {
return null;
}
return JpaWrapper.createEntityManagerFactoryProxy(entityManagerFactory);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
示例5: entityManagerFactoryMySQL
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
@Produces
@ApplicationScoped
@Default
@Startup
public EntityManagerFactory entityManagerFactoryMySQL(@InjectableProperties(file = "jpa-mysql") Map<String, String> properties) {
PersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
return persistenceProvider.createEntityManagerFactory("MySQL", properties);
}
示例6: getEntityManagerFactory
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
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;
}
示例7: getEntityManagerFactory
import javax.persistence.spi.PersistenceProvider; //導入方法依賴的package包/類
private static 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;
}