-->
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.  [ 3 posts ] 
Author Message
 Post subject: How do i identify Duplicate unique primary key exception?
PostPosted: Thu Sep 01, 2005 1:52 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Is there any way in which i can identify that, if an exception occurs while saving an object through hibernate, then whether the cause of the exception is "Duplicate unique primary key". Something similar to what i do in case of StaleObjectException as follows:

Code:
try {

  //save object through Hibernate
}
catch (Exception tapce) {
           
           Throwable te = tapce;
           while (te != null) {
               if (te.getCause() instanceof StaleObjectStateException) {
                   logger.error("Some one changed this object");
                   break;
               }
               te = te.getCause();
           }
           
       }


Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 2:46 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Take a look at the Direct Known Subclasses at http://www.hibernate.org/hib_docs/v3/ap ... ption.html and http://www.hibernate.org/hib_docs/v3/ap ... ption.html .

Perhaps ConstraintViolationException.getSQLException() is close enough.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 3:39 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Thanks a lot. Thats what i was looking for.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.