-->
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: Why did that delete fail?
PostPosted: Thu Apr 05, 2007 11:16 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
I'm written a deleteContact(Contact) method, but I would like to improve its error handling.

Currently, I just catch the exception that is thrown and wrap it in a new exception with the message "Could not delete contact" which is then displayed to the user.

I would like to give the user a more specific error message e.g. "Could not delete contact because contact is referenced elsewhere in the system". I could do this by checking the error code on the SQLException object, but that number is vendor specific. Does Hibernate provide me a way of finding out in a vendor-neutral fashion if an integrity constraint has failed?

I don't want to have to do all these checks myself before attempting the delete.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 2:34 pm 
Beginner
Beginner

Joined: Sun Nov 16, 2003 3:04 pm
Posts: 24
This isn't the answer, but could be a step in the right direction:
I wrap hibernate in spring, and spring rethrows hibernate exceptions as its own. One that you are looking for would be the spring exception "DataIntegrityViolationException". I actually catch this one to do just as you say and make easy error messages to the user (I actually use an annotation and aspect to make it simple for me to make easy error messages by just annotating a service method call which maps the error key to the thrown exception).
I'm guessing Spring isn't doing anything vendor specific to do this, so you may want to dig into the guts of spring to see how they do it.

For the record, the fully qualified exception I'm catching is:
org.springframework.dao.DataIntegrityViolationException


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.