users
[Top] [All Lists]

Re: [cinjug-users] Hibernate - increment generator

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] Hibernate - increment generator
From: "Edward Sumerfield" <esumerfd@xxxxxxxxxxxxxx>
Date: Tue, 13 Mar 2007 12:23:10 -0400
Delivered-to: mailing list users@cinjug.org
Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=etuxZPKzLCPgrD/Z7wWzf8g+TNoFxQi3D0rHvR0OxqcBb4dr15FNzRNYCVomlZ5GFKsHyMHkultDEa9fnMNCTV+a99sdX2s2gnN3GzD8wy57UBNFzyz5W72tfkJ+ujyQQNZ5YqNSR5lUkVYaTuZdrio45++3oDaHCLLq0aGvE1M=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:reply-to:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=FTdQCrBi8LGTE2tD5v1GS7vzB579urjaNhIr6Y5HK4AzpDQYNFmuj5uxvbcl0sU49MiD8xNb0E79algycYRN3vrvboZgS4t6cFaCJOfQKnzv4gImzDqm2t3x3uw2wiTsp0Ea/f8VT5Kc1LF9sYLE1jgWbO9OWH7kIHiEXzXfDYg=
In-reply-to: <4e2988cc0703130757w58163019sd93564990f48f142@mail.gmail.com>
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <4e2988cc0703130757w58163019sd93564990f48f142@mail.gmail.com>
Reply-to: esumerfd@xxxxxxxxxxxxxx
Sender: esumerfd@xxxxxxxxx
In a clustered environment or an environment with two applications
sharing the same tables and doing inserts. It is mandatory that a
database based sequence management solution is used.

This can be the built in sequences as you mentioned. You could build
your own hibernate sequence generator and plug that in, it would have
to manage a common locking structure etc etc. but if DB2 has sequences
that that is the approach to take.

Perhaps I should ask, why is it "too late" to add sequences. I am not
a DB2 expert but from a hibernate/oracle background I would create the
sequence, adjust the hibernate configuration and everything else would
work. If you have existing data then you would have to set the next
sequence value to the value of max(primary key) + x but that is just
SQL so not hard. No code should need to be changed.

On 3/13/07, Kumar <kumarkakani@xxxxxxxxx> 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



--
Ed

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