-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 4 not auto flushing during before completion phase
PostPosted: Mon May 14, 2012 4:19 pm 
Newbie

Joined: Mon May 14, 2012 4:12 pm
Posts: 2
Hibernate 4.1.0.Final isn´t auto flushing during before completion phase when using JTA (CMT) under Spring 3.1.0.RELEASE and JBoss AS 7.1.

I´ve set hibernate.transaction.factory_class to org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory and hibernate.transaction.jta.platform to org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform. My transaction manager bean is a org.springframework.transaction.jta.JtaTransactionManager configured bean.

Then, logging (TRACE mode) shows me the following info:

15:23:58,555 TRACE [org.springframework.transaction.interceptor.TransactionInterceptor] (http--127.0.0.1-8080-1) Completing transaction for...

15:23:58,557 TRACE [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Triggering beforeCommit synchronization
15:23:58,558 TRACE [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Triggering beforeCompletion synchronization
15:23:58,559 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] (http--127.0.0.1-8080-1) Closing JPA EntityManager
15:23:58,560 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Initiating transaction commit
15:23:58,561 TRACE [org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization] (http--127.0.0.1-8080-1) JTA sync : beforeCompletion()
15:23:58,562 TRACE [org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl] (http--127.0.0.1-8080-1) Transaction before completion callback
15:23:58,564 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) before transaction completion
15:23:58,566 TRACE [org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization] (http--127.0.0.1-8080-1) JTA sync : afterCompletion(3)
15:23:58,567 TRACE [org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl] (http--127.0.0.1-8080-1) Transaction after completion callback [status=3]
15:23:58,568 TRACE [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) after transaction completion
15:23:58,569 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Aggressively releasing JDBC connection
15:23:58,570 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) after transaction completion
15:23:58,571 DEBUG [org.hibernate.ejb.EntityManagerImpl] (http--127.0.0.1-8080-1) Closing entity manager after transaction completion
15:23:58,572 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) Closing session
15:23:58,573 TRACE [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Closing logical connection
15:23:58,574 TRACE [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler] (http--127.0.0.1-8080-1) Handling invocation of connection method [close]
15:23:58,575 TRACE [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler] (http--127.0.0.1-8080-1) Invalidating connection handle
15:23:58,576 TRACE [org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl] (http--127.0.0.1-8080-1) Closing JDBC container [org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl@17072bf]
...

HOWEVER, IF I use org.springframework.orm.jpa.JpaTransactionManager, instead of JtaTransactionManager, adjusting the configurations above, logging shows me:

16:40:36,014 TRACE [org.springframework.transaction.interceptor.TransactionInterceptor] (http--127.0.0.1-8080-1) Completing transaction for...

16:40:36,015 TRACE [org.springframework.orm.jpa.JpaTransactionManager] (http--127.0.0.1-8080-1) Triggering beforeCommit synchronization
16:40:36,015 TRACE [org.springframework.orm.jpa.JpaTransactionManager] (http--127.0.0.1-8080-1) Triggering beforeCompletion synchronization
16:40:36,016 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] (http--127.0.0.1-8080-1) Initiating transaction commit
16:40:36,016 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] (http--127.0.0.1-8080-1) Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@2d885a]
16:40:36,017 DEBUG [org.hibernate.engine.transaction.spi.AbstractTransactionImpl] (http--127.0.0.1-8080-1) committing
16:40:36,017 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) Automatically flushing session
16:40:36,017 TRACE [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Flushing session
16:40:36,018 DEBUG [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Processing flush-time cascades
16:40:36,018 TRACE [org.hibernate.engine.internal.Cascade] (http--127.0.0.1-8080-1) Processing cascade ACTION_PERSIST_ON_FLUSH for: br.gov.tcu.sgos.modelo.entidade.ordemservico.OrdemServico
16:40:36,019 TRACE [org.hibernate.engine.spi.CascadingAction] (http--127.0.0.1-8080-1) Cascading to persist on flush: br.gov.tcu.sgos.modelo.entidade.contrato.Contrato
16:40:36,020 TRACE [org.hibernate.engine.internal.Cascade] (http--127.0.0.1-8080-1) Done processing cascade ACTION_PERSIST_ON_FLUSH for: br.gov.tcu.sgos.modelo.entidade.ordemservico.OrdemServico
16:40:36,021 DEBUG [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Dirty checking collections
16:40:36,021 TRACE [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Flushing entities and processing referenced collections
16:40:36,022 TRACE [org.hibernate.persister.entity.AbstractEntityPersister] (http--127.0.0.1-8080-1) br.gov.tcu.sgos.modelo.entidade.ordemservico.OrdemServico.descricao is dirty
16:40:36,022 TRACE [org.hibernate.event.internal.DefaultFlushEntityEventListener] (http--127.0.0.1-8080-1) Found dirty properties [[br.gov.tcu.sgos.modelo.entidade.ordemservico.OrdemServico#5]] : [Ljava.lang.String;@1882506
16:40:36,023 TRACE [org.hibernate.event.internal.DefaultFlushEntityEventListener] (http--127.0.0.1-8080-1) Updating entity: [br.gov.tcu.sgos.modelo.entidade.ordemservico.OrdemServico#5]
16:40:36,024 TRACE [org.hibernate.engine.internal.Versioning] (http--127.0.0.1-8080-1) Incrementing: 2 to 3
16:40:36,026 TRACE [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Processing unreferenced collections
16:40:36,026 TRACE [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Scheduling collection removes/(re)creates/updates
16:40:36,027 DEBUG [org.hibernate.event.internal.AbstractFlushingEventListener] (http--127.0.0.1-8080-1) Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects

SO, is something missing? Some additional configuration? Using JpaTransactionaManager everything works as expected, but when using JtaTransactionManager there is no auto flush during the before completion phase.

Could you please help me?

I´m looking forward to hearing good news from you.

Thank you.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 not auto flushing during before completion phase
PostPosted: Tue May 15, 2012 2:45 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I suggest you to get the sources of hibernate and then debug by putting a breakpoint into CMTTransaction#beforeTransactionCommit

CMTTransaction.java
Code:
@Override
   protected void beforeTransactionCommit() {
      boolean flush = ! transactionCoordinator().getTransactionContext().isFlushModeNever() &&
            ! transactionCoordinator().getTransactionContext().isFlushBeforeCompletionEnabled();
      if ( flush ) {
         // if an exception occurs during flush, user must call rollback()
         transactionCoordinator().getTransactionContext().managedFlush();
      }
   }


by debugging look which of the 2 conditions lead to boolean flush becoming false.
If it is the ladder, then you can set it to true by setting property
hibernate.transaction.flush_before_completion
in your configuration.


Top
 Profile  
 
 Post subject: Re: Hibernate 4 not auto flushing during before completion phase
PostPosted: Tue May 15, 2012 10:56 am 
Newbie

Joined: Mon May 14, 2012 4:12 pm
Posts: 2
pb00067: I´ve checked what you´d suggested and these "flags" are both false, so if this code were executed we would have flush set do true. But I think this code isn´t being executed because I´m using Spring to manage JBossJTA transactions. Logging shows me:

11:45:31,371 TRACE [org.springframework.transaction.interceptor.TransactionInterceptor] (http--127.0.0.1-8080-1) Completing transaction for...
11:45:31,373 TRACE [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Triggering beforeCommit synchronization
11:45:31,374 TRACE [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Triggering beforeCompletion synchronization
11:45:31,375 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] (http--127.0.0.1-8080-1) Closing JPA EntityManager
11:45:31,376 DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Initiating transaction commit
11:45:31,377 TRACE [org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization] (http--127.0.0.1-8080-1) JTA sync : beforeCompletion()
11:45:31,378 TRACE [org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl] (http--127.0.0.1-8080-1) Transaction before completion callback
11:45:31,379 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) before transaction completion
11:45:31,380 TRACE [org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization] (http--127.0.0.1-8080-1) JTA sync : afterCompletion(3)
11:45:31,381 TRACE [org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl] (http--127.0.0.1-8080-1) Transaction after completion callback [status=3]
11:45:31,382 TRACE [org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl] (http--127.0.0.1-8080-1) after transaction completion
11:45:31,382 DEBUG [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Aggressively releasing JDBC connection
11:45:31,383 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) after transaction completion
11:45:31,383 DEBUG [org.hibernate.ejb.EntityManagerImpl] (http--127.0.0.1-8080-1) Closing entity manager after transaction completion
11:45:31,384 TRACE [org.hibernate.internal.SessionImpl] (http--127.0.0.1-8080-1) Closing session
11:45:31,384 TRACE [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Closing logical connection
11:45:31,385 TRACE [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler] (http--127.0.0.1-8080-1) Handling invocation of connection method [close]
11:45:31,385 TRACE [org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler] (http--127.0.0.1-8080-1) Invalidating connection handle
11:45:31,386 TRACE [org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl] (http--127.0.0.1-8080-1) Closing JDBC container [org.hibernate.engine.jdbc.internal.JdbcResourceRegistryImpl@146d34f]
11:45:31,387 TRACE [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (http--127.0.0.1-8080-1) Logical connection closed
11:45:31,387 TRACE [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Triggering afterCommit synchronization
11:45:31,388 TRACE [org.springframework.transaction.jta.JtaTransactionManager] (http--127.0.0.1-8080-1) Triggering afterCompletion synchronization

I´ve posted a thread about it in the Spring forum too (http://forum.springsource.org/showthrea ... post412589).

It seems to be something about how Spring calls transaction synchronization when using JTA, but we don´t know it for sure.

Any other suggestions?

Thanks for answering.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.