Can someone give me clues on how to best implement this requirement please?
I am implementing a [b]User[/b] class that has a [b]userName[/b] property that must be unique. So, if a user specifies a username that is not unique, I must detect and report this back to the user.
In the the mapping file for User and in the database table I have specified [b]userName[/b] as being a unique field.
When I create and save a new [b]User[/b] object, I am relying on Hibernate to tell me that the unique key constraint has been. Hibernate, of course, does not allow the save and generates an exception. But the exception is very general:
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
...
I can't use this to determine whether that the unique key constraint, in particular, has been violated.
I assume, therefore, that I may be using the wrong approach to implementing this requirement.
Can someone please advise?
Thanks.
|