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.
|
|