-->
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.  [ 3 posts ] 
Author Message
 Post subject: duplicate key violates unique constraint
PostPosted: Wed Jun 14, 2006 5:12 am 
Newbie

Joined: Wed Jun 14, 2006 4:53 am
Posts: 1
Location: Munich
I use a native generator with postgres.
My problem: Adding an entry manually to the database and increasing the sequence throws an ConstraintViolationException: (duplicate key violates unique constraint) while the SessionFactory is open calling session.saveObject(o).

It seems like Hibernate doesn't update the sequence count internally. Is there any setting? or mapping property to keep it synchron ?

Tearing down "SessionFactory.close()" and "buildSessionFactory" again gets the right sequence count..


Hibernate version:
Hibernate 3.0.5

Mapping documents:
<generator class="native">
<param name="sequence">my_sequence</param>
</generator>

_________________
Hibernate is fancy :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 7:40 am 
Newbie

Joined: Sat Jun 17, 2006 8:52 am
Posts: 5
I had problems with native generator and postgres too. try class="sequence" instead of class="native".

Hope that helps

Kolja


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 7:19 am 
Newbie

Joined: Mon Mar 27, 2006 5:58 am
Posts: 6
I use Postgres 8.0
The following class fragment works very good for me:

<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="`ID`" sql-type="BIGINT"/>
<generator class="native">
</generator>
</id>

SchemaExport will create something like hibernate_sequence at the database.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.