-->
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: Detecting Unique Key Violation
PostPosted: Thu Sep 30, 2004 9:48 am 
Newbie

Joined: Thu Sep 30, 2004 9:21 am
Posts: 3
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.


Top
 Profile  
 
 Post subject: Check it in the application code beforehand
PostPosted: Thu Sep 30, 2004 11:09 am 
Newbie

Joined: Thu Sep 30, 2004 10:31 am
Posts: 4
You should do a query before you try to save the record for that username.


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.