users
[Top] [All Lists]

Re: [cinjug-users] Hibernate - increment generator

To: Kumar <kumarkakani@xxxxxxxxx>
Subject: Re: [cinjug-users] Hibernate - increment generator
From: "James Carman" <james@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 12 Sep 2007 15:43:54 -0400
Cc: saki <saki@xxxxxxxx>, users@xxxxxxxxxx
Delivered-to: mailing list users@xxxxxxxxxx
In-reply-to: <4e2988cc0709121059u79217f3bxb34da303a5ae0d30@xxxxxxxxxxxxxx>
Mailing-list: contact users-help@xxxxxxxxxx; run by ezmlm
References: <4e2988cc0703130757w58163019sd93564990f48f142@xxxxxxxxxxxxxx> <12639733.post@xxxxxxxxxxxxxxx> <f2e8eedf0709120958x4066e7cfidcdc65f1d0d10b18@xxxxxxxxxxxxxx> <4e2988cc0709121059u79217f3bxb34da303a5ae0d30@xxxxxxxxxxxxxx>
Sender: jcarman@xxxxxxxxxxxxxxxxxxxx
The main benefit (for others monitoring this thread) of the UUID
implementation is that your object's identity is known at
instantiation time and is not dependent upon the database.  Therefore,
you can base the hashCode() method (and equals() of course) on that id
value and it will not change throughout the life of the object.  This
is especially useful when you're using HashMaps for your one-to-many
collections (as many do).   You can put all this hashCode()/equals()
logic in one superclass and have all your entity classes extend it.


On 9/12/07, Kumar <kumarkakani@xxxxxxxxx> wrote:
> Yes, we tried sequence objects first, which worked locally (But it did not
> workout in our production environment because we were using an older version
> of DB2. We also tried identity columns which worked fine, but back-up and
> other maintenance stuff on the database was difficult, according to our
> DBA.)
>
> So we tried UUID and it worked perfectly alright. And yes, it solved a lot
> of our problems too, with multiple apps like (.NET, COBOL and even other
> Java apps) inserting rows to the same tables.
>
> Thanks for the replies folks! This forum helped us a lot.
>
> Kumar
>
>
> On 9/12/07, James Carman <james@xxxxxxxxxxxxxxxxxxxx> wrote:
> > Have you tried using a UUID instead?  That solved a LOT of our problems!
> >
> > On 9/12/07, saki <saki@xxxxxxxx> wrote:
> > >
> > > 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.
> > >
> > >
> > > ---------
> > > You may unsubscribe from this mailing list
> > > by sending a blank email addressed to:
> > > users-unsubscribe@xxxxxxxxxx
> > >
> > > --
> > > Find additional help by sending a blank email
> > > addressed to:
> > > users-help@xxxxxxxxxx
> > >
> > >
> >
> > ---------
> > You may unsubscribe from this mailing list
> > by sending a blank email addressed to:
> > users-unsubscribe@xxxxxxxxxx
> >
> > --
> > Find additional help by sending a blank email
> > addressed to:
> > users-help@xxxxxxxxxx
> >
> >
>
>

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