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.  [ 5 posts ] 
Author Message
 Post subject: how to extract the ContstraintViolation from the DataAccessE
PostPosted: Fri May 30, 2008 12:30 pm 
Newbie

Joined: Fri May 30, 2008 12:15 pm
Posts: 7
Hi all,

Sorry for this basic question but how can I extract the nested ConstraintViolationException from the DataAccesException that I'm catching? I want to use the getNextException() method in order to drill down to the insert which is causing the problem, but that method is not available in DataAccessException.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 3:24 pm 
Beginner
Beginner

Joined: Mon Nov 20, 2006 2:46 pm
Posts: 32
I think that is a Spring class actually. In any case, did you try getRootCause()?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 4:48 pm 
Newbie

Joined: Fri May 30, 2008 12:15 pm
Posts: 7
Hi Ray,

I realize that I'd really asked a Java question here but this topic still could be some easy credits for someone :)

getRootCause() returns a Throwable - which I know is a ConstraintViolationException thanks to my IDE. What I really wanted to do is set up my catch block to inspect the returned throwable object determine if it's a ConstraintViolationException and then use the getNextException() method of the ConstraintViolationException iterate through the SQL exceptions.

So this is what I did .. (code borrowed from OnJava)
Code:
      } catch (DataAccessException e) {   
         Throwable t = e.getMostSpecificCause();         
         if (t instanceof ConstraintViolationException) {               
            SQLException ex = (SQLException) t.getCause();   
            while(ex != null){
                 while(t != null) {
                     System.out.println("Cause:" + t);
                     t = t.getCause();
                 }
                 ex.printStackTrace();
                 ex = ex.getNextException();
            }
         }


The thing is the error message was still just as cryptic and had been bubbled up to the original DataAccessException (actually a DataIntegrityViolationException) which reads:

Error for batch element #1: Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=270, COLNO=1" is not allowed.

Is there a way to get the error to tell me the human friendly table name and column name that failed?

Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 31, 2008 8:04 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
if the database is not telling it (some db to not inform possible hackers about table names), than Hibernate cannot know.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 01, 2008 6:22 pm 
Newbie

Joined: Fri May 30, 2008 12:15 pm
Posts: 7
Thanks for the FYI :) Can anyone tell me how to set up DB2 to tell me the table and column names in my error messages? I'm running the database locally on my workstation.


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