-->
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: 2 load balanced servers +<generator class="increment" />
PostPosted: Mon Jun 15, 2009 6:37 am 
Newbie

Joined: Fri Mar 11, 2005 11:18 am
Posts: 8
I have 2 servers that are load balanced each of them having Glassfish+Spring + Hibernate.

From time to time i get this PK exception saying that an existing value is already inserted in the database...

This happens when i do not use flush automatically ....BUT work after testing when i use flush() the session.

My question is having 2 servers and that use <generator class="increment" /> for an entity is safe to use with flush() ????

I undestand that if i do not use flush() both server may receive same value as PK from database since one server may ask before the second flushing into the database.
So error makes sense in that case....BUT i repeat if i use flush() and @transactional is safe enough ...???

THX


Top
 Profile  
 
 Post subject: Re: 2 load balanced servers +<generator class="increment" />
PostPosted: Mon Jun 15, 2009 10:11 am 
Newbie

Joined: Fri Mar 11, 2005 11:18 am
Posts: 8
Ok i found the problem thx to maxb_ from hiberante irc channel who pointe me the HIbernate manual.

http://docs.jboss.org/hibernate/stable/ ... -generator

Also int the book Java Persistence with Hiberante there is :

"At Hibernate startup, this generator reads the
maximum (numeric) primary key column value
of the table and increments the value by one
each time a new row is inserted. The generated
identifier is of type long, short, or
int. This generator is especially efficient if
the single-server Hibernate application has
exclusive access to the database but should
not be used in any other scenario."


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.