本文整理了Java中javax.persistence.EntityManager.getEntityManagerFactory()
方法的一些代码示例,展示了EntityManager.getEntityManagerFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.getEntityManagerFactory()
方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:getEntityManagerFactory
[英]Return the entity manager factory for the entity manager.
[中]返回实体管理器的实体管理器工厂。
代码示例来源:origin: rapidoid/rapidoid
@Override
public EntityManagerFactory getEntityManagerFactory() {
return em.getEntityManagerFactory();
}
代码示例来源:origin: rapidoid/rapidoid
@Override
public EntityManagerFactory getEntityManagerFactory() {
return em().getEntityManagerFactory();
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Returns whether the named query with the given name exists.
*
* @param em must not be {@literal null}.
* @param queryName must not be {@literal null}.
* @return
*/
private static boolean hasNamedQuery(EntityManager em, String queryName) {
/*
* See DATAJPA-617, we have to use a dedicated em for the lookups to avoid a
* potential rollback of the running tx.
*/
EntityManager lookupEm = em.getEntityManagerFactory().createEntityManager();
try {
lookupEm.createNamedQuery(queryName);
return true;
} catch (IllegalArgumentException e) {
LOG.debug("Did not find named query {}", queryName);
return false;
} finally {
lookupEm.close();
}
}
代码示例来源:origin: kiegroup/jbpm
protected EntityManager getEntityManager(Command<?> command) {
EntityManager em = (EntityManager) txm.getResource(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER);
if (em != null && em.isOpen() && em.getEntityManagerFactory().equals(emf)) {
return em;
}
return null;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public static boolean isTransactionalEntityManager(EntityManager em) {
EntityManager target = EntityManagerFactoryUtils.doGetTransactionalEntityManager(
em.getEntityManagerFactory(), em.getProperties(), true);
return target != null;
}
代码示例来源:origin: rapidoid/rapidoid
public boolean isLoaded(Object entity) {
return em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded(entity);
}
代码示例来源:origin: rapidoid/rapidoid
public boolean isLoaded(Object entity, String attribute) {
return em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded(entity, attribute);
}
代码示例来源:origin: rapidoid/rapidoid
public Object getIdentifier(Object entity) {
return em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier(entity);
}
代码示例来源:origin: spring-projects/spring-data-jpa
validatingEm = getEntityManager().getEntityManagerFactory().createEntityManager();
validatingEm.createQuery(query);
代码示例来源:origin: AxonFramework/AxonFramework
private void addNamedQueriesTo(EntityManager entityManager) {
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
entityManagerFactory.addNamedQuery(LOAD_SAGA_NAMED_QUERY, entityManager.createQuery(LOAD_SAGA_QUERY));
entityManagerFactory.addNamedQuery(
DELETE_ASSOCIATION_NAMED_QUERY, entityManager.createQuery(DELETE_ASSOCIATION_QUERY)
);
entityManagerFactory.addNamedQuery(
FIND_ASSOCIATION_IDS_NAMED_QUERY, entityManager.createQuery(FIND_ASSOCIATION_IDS_QUERY));
entityManagerFactory.addNamedQuery(
DELETE_ASSOCIATIONS_NAMED_QUERY, entityManager.createQuery(DELETE_ASSOCIATIONS_QUERY)
);
entityManagerFactory.addNamedQuery(
FIND_ASSOCIATIONS_NAMED_QUERY, entityManager.createQuery(FIND_ASSOCIATIONS_QUERY)
);
entityManagerFactory.addNamedQuery(DELETE_SAGA_NAMED_QUERY, entityManager.createQuery(DELETE_SAGA_QUERY));
entityManagerFactory.addNamedQuery(UPDATE_SAGA_NAMED_QUERY, entityManager.createQuery(UPDATE_SAGA_QUERY));
}
代码示例来源:origin: stackoverflow.com
em.getTransaction().commit();
PersistenceUnitUtil unitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil();
代码示例来源:origin: kiegroup/jbpm
if (em != null && em.isOpen() && em.getEntityManagerFactory().equals(emf)) {
sharedEM = true;
return em;
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test() {
SimpleEntity[] entities = new SimpleEntity[2];
entities[0] = new SimpleEntity();
entities[0].name = "test";
TransactionUtil.doInJPA( this::sessionFactory, em -> {
entities[1] = em.merge( entities[0] );
assertNotNull( em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier( entities[1] ) );
} );
// Call as detached entity
try ( SessionFactory sessionFactory = sessionFactory() ) {
assertNotNull( sessionFactory.getPersistenceUnitUtil().getIdentifier( entities[1] ) );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testJPQLUpperAttributeValueBindParameterType() throws Exception {
doInJPA( this::entityManagerFactory, entityManager -> {
//tag::basic-attribute-converter-query-parameter-converter-object-example[]
SessionFactory sessionFactory = entityManager.getEntityManagerFactory()
.unwrap( SessionFactory.class );
MetamodelImplementor metamodelImplementor = (MetamodelImplementor) sessionFactory.getMetamodel();
Type captionType = metamodelImplementor
.entityPersister( Photo.class.getName() )
.getPropertyType( "caption" );
Photo photo = (Photo) entityManager.createQuery(
"select p " +
"from Photo p " +
"where upper(caption) = upper(:caption) ", Photo.class )
.unwrap( Query.class )
.setParameter( "caption", new Caption("Nicolae Grigorescu"), captionType)
.getSingleResult();
//end::basic-attribute-converter-query-parameter-converter-object-example[]
assertEquals( "Dorobantul", photo.getName() );
} );
}
代码示例来源:origin: Impetus/Kundera
/**
* Gets the persistence unit.
*
* @return the persistence unit
*/
private static String getPersistenceUnit()
{
return (String) em.getEntityManagerFactory().getProperties().get(Constants.PERSISTENCE_UNIT_NAME);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testMaxSize() {
doInJPA( this::entityManagerFactory, entityManager -> {
EntityManagerFactory entityManagerFactory = entityManager.getEntityManagerFactory();
SessionFactory sessionFactory = entityManagerFactory.unwrap( SessionFactory.class );
assertEquals(
expectedQueryStatisticsMaxSize(),
sessionFactory.getSessionFactoryOptions().getQueryStatisticsMaxSize()
);
StatisticsImplementor statistics = (StatisticsImplementor) sessionFactory.getStatistics();
for ( int i = 0; i < 10; i++ ) {
statistics.queryExecuted( String.valueOf( i ), 100, i * 1000 );
}
assertEquals( 1000, statistics.getQueryStatistics( "1" ).getExecutionTotalTime() );
for ( int i = 100; i < 300; i++ ) {
statistics.queryExecuted( String.valueOf( i ), 100, i * 1000 );
}
assertEquals( 0, statistics.getQueryStatistics( "1" ).getExecutionTotalTime() );
} );
}
}
代码示例来源:origin: hibernate/hibernate-orm
entityManager.getEntityManagerFactory().getCache().evict( Person.class );
代码示例来源:origin: hibernate/hibernate-orm
entityManager.getEntityManagerFactory().getCache().evictAll();
代码示例来源:origin: Impetus/Kundera
/**
* @param entityClassName
* @param em
* @return
*/
public static Class<?> getEntityClass(String entityClassName, EntityManager em) {
MetamodelImpl metamodel = (MetamodelImpl) em.getEntityManagerFactory().getMetamodel();
Class<?> entityClass = metamodel.getEntityClass(entityClassName);
return entityClass;
}
代码示例来源:origin: hibernate/hibernate-orm
SessionImplementor sessionImplementor = entityManager.unwrap( SessionImplementor.class );
SessionFactory sessionFactory = entityManager.getEntityManagerFactory().unwrap( SessionFactory.class );
PersistenceUnitUtil persistenceUnitUtil = entityManager.getEntityManagerFactory().getPersistenceUnitUtil();
内容来源于网络,如有侵权,请联系作者删除!