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.  [ 1 post ] 
Author Message
 Post subject: Hibernate first level cache & transaction
PostPosted: Tue May 13, 2008 10:38 am 
Newbie

Joined: Tue May 13, 2008 9:50 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: hibernate3.0.5.jar

Mapping documents:

Code between sessionFactory.openSession() and session.close():
We use Session Beans with CMP, within that we use hibernate for persistence (instead of entity beans). if I am not wrong, hibernate transaction will attach itself to container transaction. (sessionFactory.getCurrentSession())

Full stack trace of any exception that occurs: NO Exception

Name and version of the database you are using: DB2 9.1

The generated SQL (show_sql=true): Hibernate: update PROCESS_RUN set COMPLETED_BATCHES=COMPLETED_BATCHES+1, END_DTTM=getDate() where PROCESS_RUN_ID=?

Debug level Hibernate log excerpt:

Description:

We are using MDB, and every bean after completing its processing, updates the PROCESS_RUN table (update PROCESS_RUN set COMPLETED_BATCHES=COMPLETED_BATCHES+1, END_DTTM=getDate() where PROCESS_RUN_ID=?). This way we can keep track of number of beans that has finished processing. if total number of batches == completed, we know the processing has finished and we can notify the user.

Problem: This solution works fine with low volumes, with higher volume I have seen that completed batches is always less than total batches even if all the batches successful.

scenario: total batches = 2, completed = 0;
if two threads execute the update SQL at the same time, and they refer to same tuple in the database. both of these threads will have different objects (java identity) because they are in different hibernate session. Therefore both will have PROCESS_RUN object with completed batches = 0, and both will end up doing completed batches = completed batches + 1 = 1 and persist. therefore, though the completed batches should be 2, it ends up in 1.

Select for update (lockmode.upgrade) din't help either, and it effects the performance as well.

I will appreciate any suggestions.

_________________
Farwaha


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

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.