-->
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.  [ 1 post ] 
Author Message
 Post subject: Unique constraint doesn't work when using custom identifier
PostPosted: Sat Mar 02, 2013 5:24 pm 
Newbie

Joined: Wed Feb 08, 2012 2:09 am
Posts: 5
Hi,

I have created a custom identifier generator. On my id property, of type long, I added a @GenericGenerator annotation and passed the name to the @GeneratedValue annotation.

The entity has a uniqueConstraint on 3 columns, one of which is an id of another entity. Something like:

@Table(name = "entity",
uniqueConstraints = {@UniqueConstraint(columnNames = {"resource_id", "source", "destination"})})

In a test I created two entities that violate the uniqueness (they have the same resource entity and source and destination values). Saving the entities passes, but trying to find all entities of the table fails with a unique constraint violation.

If I remove the custom generator (so using the native one), the test passed. Also, trying to flush the session in the generator makes no difference. I looked at the generated schema and the constraint is there. So my guess is that the 2nd entity is not really saved to the db.

How can I solve this?
Regards,
Ittay


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

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.