Announcement Announcement Module
No announcement yet.
Hibernate behaves strange while data manipulation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate behaves strange while data manipulation


    i am running in a strange problem while developing code running in a web application (cocoon):

    I open a transaction like that (the transaction manager is a hibernate3.HibernateTransactionManager, nothing fancy):

    TransactionStatus mStatus = getTransactionManager().getTransaction(new DefaultTransactionDefinition());

    read some objects from the database via a HibernateCallback and a criteria query

    change some of the objects i fetched do a update and a flush

    SessionFactoryUtils.getSession(getSessionFactory() , true).flush();

    with that i see the update statement in the console, so i do a commit:


    and i see the variables in the mStatus object change:
    completed from false to true
    synchronisedWithTransaction from true to false ?!?
    transaction from a transaction object to null.

    yea! it works fine :-) I see the changes in the database. Until i try to change the same objects again. That sometimes works, but a kind of randomly stops. When it stops working, it hangs while it tries the update, and it looks like it fails because something dirty happened before, locking the table where the objects reside.

    So long was i not able to see some pattern when the "dirt" is done. I am driving in a web server and it looks like i get a new session for each of the processes.

    Any additional information which could be of help?

    Anyone who has an idea where to start looking?

    Best regards

    Søren Krum

    I use declarative transactions, if does a difference.

    <tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
    <!-- the transactional semantics... -->
    <tx:method name="*" />
    <aopointcut id="applicationServiceOperation"
    expression="execution(* no.mypackage.*Service.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="applicationServiceOperation" />

    Some further investigations showed that the process blocks when the objects are changed from different instances of hibernate Session, what seems to point in the direction that (i assume that different Session use different db cons?!?) the commit does not all the time really hit the database... But there is still the question why does it hit sometimes...
    Last edited by sorenk; Jul 10th, 2009, 05:24 AM.

  • #2

    there is not enougth information, Can you post de stacktrace?

    Seems that you have a long time transaction (that already has flushed some sql to database) running when other thread try to use an object used in the long transaction. Depending of database you are using you can play with isolation level and this may be a problem or not.

    Are you using MySql with innoDB?.

    if is that case, see

    hope that help

    -- Chelu


    • #3

      Your suggestions brought me on the right way, thanks for that :-)

      I messed a bit with declarative transactions and some programmatic transactions in between. NOT recommended!

      Thanks for your help