Hi
Trying to do something very simple but can't find a good solution. Any advice would be appreciated. Basically, how do you validate uniqueness of a model property and throw appropriate exception (which can be translated into a meaningful error message). Example:
Code:
class Person {
@Column
private String email;
}
I want to intercept
@PreUpdate and find out if email is being changed and if the new email clashes with another Person, throw an user defined exception (eg
PersonEmailExistsException). I understand I can provide (unique=true) to
@Column but that throws a generic HibernateException and if I have more than one unique property, I wouldn't know which column is throwing exception - and show appropriate error message.
This must be a faily common requirement and I'm sure it has been solved many times over. Anyone cares to share insights? We'll appreciate it.