users
[Top] [All Lists]

Re: [cinjug-users] Hibernate - increment generator

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] Hibernate - increment generator
From: saki <saki@xxxxxxxx>
Date: Wed, 12 Sep 2007 09:53:57 -0700 (PDT)
Delivered-to: mailing list users@xxxxxxxxxx
In-reply-to: <4e2988cc0703130757w58163019sd93564990f48f142@xxxxxxxxxxxxxx>
Mailing-list: contact users-help@xxxxxxxxxx; run by ezmlm
References: <4e2988cc0703130757w58163019sd93564990f48f142@xxxxxxxxxxxxxx>
Probably to late, but may be it will help ...

Per doc this generator should not be used in multiprocess enviroment. It's
not entirely clear from the doc, but if you look at code, you would find out
the generator reads the value from database only first time when it is used
and than it only every time increments this value ...

"increment generates identifiers of type long, short or int that are unique
only when no other process is inserting data into the same table. Do not use
in a cluster." 
 



Kumar-10 wrote:
> 
> I have a question related to Hibernate (I am not sure if this is the right
> forum to ask this. Please direct me to the right one if so).
> 
> We have a web application that uses Hibernate's increment generator to
> insert rows in DB2 tables. We have another Java application that inserts
> rows in the same DB2 tables using Hibernate's increment generator. These
> two
> applications are totally independent of each other and both have mappings
> like so:
> 
> <id name="objectId" type="int" column="TABLE_ID">
>             <generator class="increment"/>
> </id>
> 
> My question is: If both applications simultaneously try to insert rows
> into
> the same table, will we get a ConstraintViolationException? I read that
> the
> increment generator should not be used in a clustered environment (
> http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html). I am
> curious to know how Hibernate works internally. Does it lock the database
> until it generates the max. id and finishes inserting the corresponding
> row
> - all in one transaction?
> 
> Ideally, I guess we should have had the the database generate sequence
> numbers and use Hibernate's sequence generator. But at this point, I think
> it's a bit too late to make such a big change unless absolutely required.
> 
> Please advise. Thanks in advance as always.
> 
> Kumar
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Hibernate---increment-generator-tf3396487.html#a12639733
Sent from the CinJUG - Users mailing list archive at Nabble.com.


<Prev in Thread] Current Thread [Next in Thread>