本文整理了Java中javax.persistence.EntityManager.setFlushMode()
方法的一些代码示例,展示了EntityManager.setFlushMode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.setFlushMode()
方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:setFlushMode
[英]Set the flush mode that applies to all objects contained in the persistence context.
[中]设置应用于持久性上下文中包含的所有对象的刷新模式。
代码示例来源:origin: rapidoid/rapidoid
@Override
public void setFlushMode(FlushModeType flushMode) {
em.setFlushMode(flushMode);
}
代码示例来源:origin: rapidoid/rapidoid
@Override
public void setFlushMode(FlushModeType flushMode) {
em().setFlushMode(flushMode);
}
代码示例来源:origin: hibernate/hibernate-orm
private void mergeDocument(FlushModeType flushModeType, Long id) {
final EntityManager entityManager = getOrCreateEntityManager();
try {
entityManager.setFlushMode( flushModeType );
entityManager.getTransaction().begin();
DocumentA doc = entityManager.find( DocumentA.class, id );
doc.setDate( new Date() );
for ( DocumentLineA line : doc.getLines() ) {
line.setText( "Updated" );
}
DocumentLineA line = new DocumentLineA();
line.setText( "line2" );
doc.addLine( line );
entityManager.merge( doc );
entityManager.getTransaction().commit();
}
catch ( Exception e ) {
if ( entityManager != null && entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
throw e;
}
finally {
if ( entityManager != null && entityManager.isOpen() ) {
entityManager.close();
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
private Long persistDocument(FlushModeType flushModeType) {
final EntityManager entityManager = getOrCreateEntityManager();
try {
entityManager.setFlushMode( flushModeType );
entityManager.getTransaction().begin();
DocumentA doc = new DocumentA();
doc.setNumber( "1" );
doc.setDate( new Date() );
DocumentLineA line = new DocumentLineA();
line.setText( "line1" );
doc.addLine( line );
entityManager.persist( doc );
entityManager.getTransaction().commit();
return doc.getId();
}
catch ( Exception e ) {
if ( entityManager != null && entityManager.getTransaction().isActive() ) {
entityManager.getTransaction().rollback();
}
throw e;
}
finally {
if ( entityManager != null && entityManager.isOpen() ) {
entityManager.close();
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
entityManager.setFlushMode( FlushModeType.COMMIT );
Session session = entityManager.unwrap( Session.class );
session.setHibernateFlushMode( FlushMode.MANUAL );
代码示例来源:origin: kiegroup/jbpm
@Test
public void testWithDatabaseAndStartProcess() throws Exception {
// Create variable
Map<String, Object> params = new HashMap<String, Object>();
NonSerializableClass processVar = new NonSerializableClass();
processVar.setString("1234567890");
params.put(VAR_NAME, processVar);
// Persist variable
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
ut.begin();
EntityManagerFactory emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
em.joinTransaction();
em.persist(processVar);
em.close();
ut.commit();
// Generate, insert, and start process
ProcessInstance processInstance = ksession.startProcess(PROCESS_ID, params);
// Test resuls
Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
processVar = (NonSerializableClass) ((WorkflowProcessInstance) processInstance).getVariable(VAR_NAME);
Assert.assertNotNull(processVar);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testFlushModeCommitWithMapsIdAndIdentity() {
final ParentEntity parent = TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.setFlushMode( FlushModeType.COMMIT );
final ParentEntity parentEntity = new ParentEntity();
parentEntity.setData( "test" );
final ChildEntity childEntity = new ChildEntity();
parentEntity.addChild( childEntity );
entityManager.persist( parentEntity );
entityManager.persist( childEntity );
return parentEntity;
} );
TransactionUtil.doInJPA( this::entityManagerFactory, entityManager -> {
final ParentEntity parentEntity = entityManager.find( ParentEntity.class, parent.getId() );
assertNotNull( parentEntity );
assertNotNull( parentEntity.getChildren() );
assertTrue( !parentEntity.getChildren().isEmpty() );
final ChildEntity childEntity = parentEntity.getChildren().iterator().next();
assertNotNull( childEntity );
assertEquals( parentEntity.getId(), childEntity.getId() );
} );
}
代码示例来源:origin: kiegroup/jbpm
EntityManagerFactory emf = (EntityManagerFactory) context.get(ENTITY_MANAGER_FACTORY);
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
em.joinTransaction();
em.persist(processVar);
代码示例来源:origin: spring-projects/spring-integration
@Override
public Object prepareTransaction(EntityManager entityManager, boolean readOnly, String name) throws PersistenceException {
entityManager.setFlushMode(FlushModeType.COMMIT);
return super.prepareTransaction(entityManager, readOnly, name);
}
代码示例来源:origin: de.juplo.yourshouter.api/persistence-jpa
@Override
public void setFlushMode(FlushModeType type)
{
manager.setFlushMode(type);
}
代码示例来源:origin: Impetus/Kundera
@Test
public void testPersist() throws NotSupportedException, SystemException, NamingException, SecurityException,
IllegalStateException, RollbackException, HeuristicMixedException, HeuristicRollbackException
{
userTransaction = (UserTransaction) initialContext.lookup("java:comp/UserTransaction");
em.setFlushMode(FlushModeType.COMMIT);
userTransaction.begin();
CouchDBPersonJTAEntity person = new CouchDBPersonJTAEntity();
person.setPersonId("1_p");
person.setPersonName("crossdata-store");
CouchDBAddressJTAEntity address = new CouchDBAddressJTAEntity();
address.setAddressId("1_a");
address.setStreet("my street");
person.setAddress(address);
try
{
em.persist(person);
}
catch (Exception ex)
{
CouchDBAddressJTAEntity found = em.find(CouchDBAddressJTAEntity.class, "1_a");
Assert.assertNull(found);
}
userTransaction.commit();
}
代码示例来源:origin: com.agapsys.libs/web-app-toolkit
/**
* Returns an entity manager to be used by application.
*
* @param emf Entity manager factory.
* @return an entity manager to be used by application.
*/
protected EntityManager getCustomEntityManager(EntityManagerFactory emf) {
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
return em;
}
代码示例来源:origin: com.agapsys/web-app-toolkit-core
@Override
public EntityManager getInstance() {
EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT);
return em;
}
代码示例来源:origin: apache/oozie
/**
* Invoke transaction on the EntityManager
*/
public void beginTrx() {
entityManager.setFlushMode(FlushModeType.COMMIT);
entityManager.getTransaction().begin();
}
代码示例来源:origin: Jasig/uPortal
@Override
public DateDimension getDateDimensionById(long key) {
final EntityManager entityManager = this.getEntityManager();
final FlushModeType flushMode = entityManager.getFlushMode();
try {
entityManager.setFlushMode(FlushModeType.COMMIT);
return entityManager.find(DateDimensionImpl.class, key);
} finally {
entityManager.setFlushMode(flushMode);
}
}
代码示例来源:origin: org.jboss.ejb3/jboss-ejb3-jpa-int
public void setFlushMode(FlushModeType flushMode)
{
getEntityManager().setFlushMode(flushMode);
}
}
代码示例来源:origin: org.apache.deltaspike.modules/deltaspike-data-module-impl
@Override
public void setFlushMode(FlushModeType flushMode)
{
entityManager().setFlushMode(flushMode);
}
代码示例来源:origin: org.seasar.container/s2-tiger
public void setFlushMode(final FlushModeType flushMode) {
if (isTxActive()) {
final EntityManager em = getEntityManager();
em.setFlushMode(flushMode);
}
}
代码示例来源:origin: de.mhus.lib/mhu-lib-persistence
/** {@inheritDoc} */
@Override
public void setFlushMode(FlushModeType flushMode) {
log().t("flush mode",flushMode);
entityManager.setFlushMode(flushMode);
}
代码示例来源:origin: org.apache.geronimo.ext.openejb/openejb-core
public void setFlushMode(FlushModeType flushMode) {
EntityManager entityManager = getEntityManager();
try {
entityManager.setFlushMode(flushMode);
} finally {
closeIfNoTx(entityManager);
}
}
内容来源于网络,如有侵权,请联系作者删除!