users
[Top] [All Lists]

Hibernate - increment generator

To: users@xxxxxxxxxx
Subject: Hibernate - increment generator
From: Kumar <kumarkakani@xxxxxxxxx>
Date: Tue, 13 Mar 2007 10:57:00 -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:to:subject:mime-version:content-type; b=miGNjRK8jvuAuQFnth57fWDks8Ip1uQa+gVxjRD6i0HHNxMlMt/INgF3XVPaFOGAitRW1Z2qa9DuaCyRh8+8JBFjzcmDQK+24FhKRLDOelAMj/5KMxBWHZmq4hCstaFD+emwVe297OhcaG81A51Yrxl3vv+T3O12c5T/feogDCk=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=dvB/bpww7tfnJ+BhaRuVJkOpJZNUqR4oFFLAXVqBHY1Q/Po+EmbiPWRPBiif6H8BXQzM/EcgO5KRKhtk5D/f9ndCPFpU1j2bom+u1m5xbkTiML8QyKlLDSSvKVnFXB6CIMWJ0lzKgO6GIIE576wWXSiTVsVdfPbsDxhVV5U1piU=
Mailing-list: contact users-help@cinjug.org; run by ezmlm

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
<Prev in Thread] Current Thread [Next in Thread>