[1.2.4] JPA Entity Create - primary key constraint violated

405 views
Skip to first unread message

Spencer Strombotne

unread,
Apr 27, 2012, 4:02:23 PM4/27/12
to play-fr...@googlegroups.com
I've got a simple JPA entity that has two strings for a database table that already exists. I've extended the Model class so there should be an autogenerated unique primary key.

 When I try to create a new entity like:

MyObject myObject = new MyObject();
myObject.setString1(string1);
myObject.setString2(string2);
myObject.create();

The resulting insert looks like:
DEBUG ~ insert into MYOBJECT (STRING1, STRING2, id) values (?, ?, ?)

I get the exception:
ERROR ~ ORA-00001: unique constraint violated

The constraint that's being violated is the primary key. Out of curiosity I tried setting the myObject.id to something I know for certain is unique

MyObject myObject = new MyObject();
myObject.setString1(string1);
myObject.setString2(string2);
myObject.id = 99999999;
myObject.create();

This is inserted no problem. Can anyone tell me why my entity's id isn't being set to a unique long value?


Conrado

unread,
Apr 29, 2012, 12:40:55 PM4/29/12
to play-fr...@googlegroups.com
This may help you:  http://stackoverflow.com/questions/8473910/difference-between-hibernate-automatic-value-generation-strategies 

Consider that Play's Model uses "@GeneratedValue", no arguments.
Reply all
Reply to author
Forward
0 new messages