-->
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: DB genereted PKs + concurrency + Hibernate + best practices
PostPosted: Tue Mar 29, 2005 5:53 pm 
Newbie

Joined: Sun Jun 20, 2004 7:41 am
Posts: 7
Hi all,

I'm supposed to integrate a legacy database powered by Firebird with a new system and of course I'm planning to use Hibernate. The the database generates primary keys using a combination of generator + trigger which is fired before insert to overwrite user supplied PK values with the next value from the appropriate generator.

I mapped the id as:

Code:
<id name="Nr"
column="NR"
type="integer"
>
<generator class="increment"/>
</id>


and the code that inserts new rows into the table is:

Code:
...
try {
   s = getSession();
   t = s.beginTransaction();
   Serializable rtn = s.save(obj);
   t.commit();
   return rtn;
}
catch (HibernateException e) {
   if (null != t) t.rollback();
          throw e;
}
...



The whole thing seems to work, but the potential issue I'm affraid of is concurrency.
Is the approach safe so that I can be sure that I won't end up with for example three identical PK values returned to three different threads as Hibernate seems to read the max values from the table and then inserts rows (or in reverse order, firstly inserts and then reads values)??

Thanx in advance for any help.

Regards
Chris


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.