-->
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: Using @Id @GeneratedValue causes Unique Constraint violated
PostPosted: Tue Mar 11, 2008 11:40 am 
Newbie

Joined: Tue Mar 11, 2008 11:28 am
Posts: 3
Hi,

I am trying to get the hibernate annotations working for my existing code. I have installed hibernate annotations libraries as mentioned in the tutorial and it was all working fine, but... when I try to create an entity in the database, I am getting the Unique Constraint Violated error.

I am using @Id @GeneratedValue(strategy=GenerationType.AUTO) for my primary key which is an Integer.

The table where I am trying to insert the data already have 4 rows in it, I have implemented this annotation now for the entity and trying to insert data using this, where I am getting this error. I have tried with all the strategies, but still I am stuck with this.

Can anyone please throw some light in here?

Hibernate version: 3.2

Full stack trace of any exception that occurs:

WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1062, SQLState: 23000
ERROR org.hibernate.util.JDBCExceptionReporter - Duplicate entry '0' for key 1
org.hibernate.exception.ConstraintViolationException: could not insert

Name and version of the database you are using: MySql Server 5


Thanks,
Karikalan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 11:26 am 
Newbie

Joined: Wed Feb 13, 2008 7:37 am
Posts: 6
Is it possible your generator is starting by 0?

because you have 4 rows in it, with id 1,2,3,4 i suppose your insert wil fail the first 4 times, because you have already used that id.

Try 5 times when inserting, or set your generator with an initial value of 5.


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.