-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to Make increment generator always fetch value from DB
PostPosted: Thu Oct 12, 2006 4:59 am 
Newbie

Joined: Tue Jul 11, 2006 10:41 pm
Posts: 11
Hi , i was hitting this exception


Supposed i have this table called AUDIT TABLE and created a POJO for this using increment generator


Every Success Operation i will insert to this table

The Problem is , hibernate cache the max id when the application starts
and just increment the value when there is inserting to this table.


Lets say when application start my data in my table such as below
ID Name
1 logout
2 login
3 delete


Then i start my application. and perform maybe 2 operation
so the new state of the table will be something as below
ID Name
1 logout
2 login
3 delete
4 some operation
5 some operation

then here it goes the bad scenario
i manually insert with ID = 6 and Name = Test using DB console

After this , any operation i do will give me unique constraint exception.

Because Hibernate cache the max id when the application starts so it dont always fetch from database.

Any workaround / configuration to be made if i still want to user increment generator to always fetch the max value in the DB??


Or is it better to use sequence in cluster environment??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 10:04 am 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
I think this answers your question.

http://www.hibernate.org/hib_docs/v3/re ... -generator

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



If you database is supported by the identity generator then it's really easy to switch to it. In mysql just alter the field to autoincrement.

Good luck!

Marius


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.