Announcement Announcement Module
Collapse
No announcement yet.
Uncommitted transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Uncommitted transaction

    Hello,

    I'm having a strange transaction problem using Spring w/ Hibernate and JSF. On normal requests the transaction goes through as expected and produces the following log entries around the update and commit:

    Code:
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.transaction.support.TransactionSynchronizationManager] - <Initializing transaction synchronization>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [com.myproject.dao.HibernateFooDAO] - <Writing the following entity to the database: com.myproject.domain.Bar@11a9e33[bar...ect.domain.Foo@1974028,handle=test123,title=test123,description=test123,flower=77,publishedDatetime=2006-09-12 20:00:07.0]>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1b1a986] for key [org.hibernate.impl.SessionFactoryImpl@196de29] bound to thread [http-8080-Processor23]>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1b1a986] for key [org.hibernate.impl.SessionFactoryImpl@196de29] bound to thread [http-8080-Processor23]>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTemplate] - <Found thread-bound Session for HibernateTemplate>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTemplate] - <Not closing pre-bound Hibernate Session after HibernateTemplate>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.transaction.interceptor.TransactionInterceptor] - <Invoking commit for transaction on com.myproject.dao.FooDAO.writeToDatabase>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Triggering beforeCommit synchronization>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Triggering beforeCompletion synchronization>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Initiating transaction commit>
    2006/09/29 23:27:33,458 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@d766f5]>
    Hibernate: update bar set handle=?, title=?, description=?, flower=?, published_datetime=?, foo_id=? where bar_id=?
    2006/09/29 23:27:33,536 DEBUG {http-8080-Processor23} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Triggering afterCompletion synchronization>
    When I try to perform the same operation via AJAX (ajax4jsf), the entire log looks identical except for the update and commit steps, which produces:

    Code:
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.transaction.support.TransactionSynchronizationManager] - <Initializing transaction synchronization>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [com.myproject.dao.HibernateFooDAO] - <Writing the following entity to the database: com.myproject.domain.Bar@c26acd[barI...ect.domain.Foo@10cdf59,handle=test123,title=test123,description=test123,flower=73,publishedDatetime=2006-09-12 20:00:07.0]>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1e04033] for key [org.hibernate.impl.SessionFactoryImpl@196de29] bound to thread [http-8080-Processor24]>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.transaction.support.TransactionSynchronizationManager] - <Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1e04033] for key [org.hibernate.impl.SessionFactoryImpl@196de29] bound to thread [http-8080-Processor24]>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTemplate] - <Found thread-bound Session for HibernateTemplate>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTemplate] - <Not closing pre-bound Hibernate Session after HibernateTemplate>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.transaction.interceptor.TransactionInterceptor] - <Invoking commit for transaction on com.myproject.dao.FooDAO.writeToDatabase>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Triggering beforeCommit synchronization>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Triggering beforeCompletion synchronization>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Initiating transaction commit>
    2006/09/29 23:30:12,005 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@13806b6]>
    
    2006/09/29 23:30:12,021 DEBUG {http-8080-Processor24} [org.springframework.orm.hibernate3.HibernateTransactionManager] - <Triggering afterCompletion synchronization>
    The second log differs only on the second to last log entry where the Hibernate update statement should be but is missing (I added the blank line). I've attached the full log of the regular request that works and the AJAX request that doesn't. Can anyone suggest reasons that this might happen?

    Thanks for any suggestions,
    Jeff
    Last edited by jaypee; Sep 30th, 2006, 02:05 PM. Reason: "coding" log for easier reading

  • #2
    Stale data in Hibernate?

    I think this problem may be caused by stale data in a Hibernate object. When the first AJAX request updates the object, it works and is committed. When the second one comes in, somehow it's getting the pre-updated version of the same object. How can I ensure that all requests use the same set of objects and see the updates made by other requests? Behavior similar to an application scope.

    Thanks,
    Jeff

    Comment


    • #3
      To find a proper solution, you have to pinpoint the problem. ORMs (such as Hibernate) use heavily the persistence context (in HB case, the session) - I assume in your case since you are using Ajax, the sessions used for loading/saving the objects in the background behave different then you'd expect (due to the asynch nature of Ajax).
      Take your time and track the Hibernate sessions along your ajax requests - you should be able to identify the issue with some patience.

      Comment

      Working...
      X