-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem: unique constraint and mapping
PostPosted: Fri Oct 10, 2008 8:53 am 
Newbie

Joined: Fri Oct 10, 2008 8:23 am
Posts: 3
Hi!

I have a table with a technical primary-key and a typically business-key (4 attributes in a unique-constraint).

I want now that the method saveOrUpdate throw a ConstraintViolationException or something else before the database is involved when the unique-constraint is violated!

Is this possible to manage in the mapping-file?
I have found something like properties or natural-key or unique-key, but nothing of them did that what i want!?

Is there a solution?

Thanx
Michael J.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2008 5:58 am 
Newbie

Joined: Tue Oct 28, 2008 5:13 am
Posts: 2
I was facing the same problem . You can try adding the constraint to the database table.That works.

Still i am working on a solution using the mapping file

Regards,
Basent V


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2008 7:44 am 
Newbie

Joined: Fri Oct 10, 2008 8:23 am
Posts: 3
Thanx for the reply.
The constraint exists in the database.
I have found the Interceptor as solution but thats not really what i want. I want to do it with the mapping file like you! If you found a solution with the mapping file than please post it!

Regards,
Mikel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2008 6:38 pm 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
May be I don't understand what you are trying to do, but, how can you know if a unique constraint is violated before you try to save to the database? I don't think is possible to do with the mapping file, as hibernate does not have a list of the already stored values, unless you have a second level cache (and the data is in the cache)

Hibernate will throw a ConstraintViolationException, but it will be done after trying to save in the database (In fact, the exception, is the result of a database exception)

The only solution, would be to check the database before saving, to see if the key is already present in the database. I do this with foreign keys

By the way, the unique attribute of the property tag, is only useful when automatically generating the database from the mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2008 1:11 am 
Newbie

Joined: Tue Oct 28, 2008 5:13 am
Posts: 2
I guess i didnt read the question properly. I dont think it is possible to know this; before it hits the database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2008 3:56 am 
Newbie

Joined: Tue Oct 28, 2008 5:35 pm
Posts: 7
Post deleted because it was posted to wrong thread in error, please ignore.


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