-->
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: How to receive inforamation wich constraint was violated?
PostPosted: Thu Apr 28, 2005 4:33 pm 
Newbie

Joined: Thu Apr 28, 2005 3:12 pm
Posts: 7
class Person
{
String login;//unique
String email //unique
}
I would like to insert into database new Person, but before that i would like to check if in database are already objects with the same email or login. I don't want to execute 3 statements in my java code:
1. check if there is Person with the same login
2. check if there is Person with the same email
3. insert new person

If i wouldn't use Hibernate i would write stored procedure smothing like this:
CREATE PROCEDURE..

IF EXISTS(SELECT * FROM Persons WHERE login=@login)
return 1;
IF EXISTS(SELECT * FROM Persons WHERE email=@email)
return 2;

INSERT INTO Persons VALUES ...;
return 0;

So i would execute i stored procedure and received information wheter Person was added and if not - why

My question is whether in hibernate is some way to recevie information about problems during session.save(). If i simply use session.save() and in database is already person with the same email or login I will only recevie ContraintViolationHibernate without information wich contriaint was violated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 5:43 pm 
Regular
Regular

Joined: Tue Mar 22, 2005 2:27 am
Posts: 62
Your Dialect needs to implement an override of getViolatedConstraintNameExtracter() since the default just returns null.
i.e. each dialect needs to know how to parse the constraint name out of the SQLException message string.

There is an example of this in the Oracle9Dialect implementation that ships with Hibernate.


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.