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: Validating Models in @PreUpdate
PostPosted: Wed Jul 28, 2010 10:30 am 
Newbie

Joined: Tue Jul 27, 2010 3:35 pm
Posts: 1
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.


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.