-->
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: will hibernate generate unique exception code
PostPosted: Mon Aug 01, 2005 5:17 am 
Newbie

Joined: Mon Jun 13, 2005 2:02 am
Posts: 7
will i get a unique exception code generated by hibernate in case of any database exception
for example if it is a constraint violation exception if i am getting an error code along with the error message i can identify what the error is and display it to users in a userfriendly way.
thanks Sharon


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 3:14 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
HIbernate generate Hibernate generic Exceptions see

http://www.hibernate.org/hib_docs/v3/api/org/hibernate/exception/package-summary.html

Etienne.


Top
 Profile  
 
 Post subject: Hibernate exception implements Nestable
PostPosted: Mon Aug 01, 2005 5:14 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
it is possible to get to the causes.
For example code like this:
Code:
try{
      Child c = (Child) s.createQuery("from Child c where c.id = 2").uniqueResult();
      s.delete(c);
      s.flush();
    }catch( RuntimeException e ){
      System.out.println("e = " + e);
      Throwable ne = e;
      while( ne != null){
        if( ne instanceof SQLException ){
          SQLException sqle = (SQLException) ne;
          ne =  sqle.getNextException();
          System.out.println("sqle = " + sqle.getMessage());
        }else{
          ne = ne.getCause();
        }
      }
    }

Would print out
e = org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
sqle = Batch entry 0 delete from Child where id= was aborted. Call getNextException() to see the cause.
code=0
state=null
sqle = ERROR: update or delete on "child" violates foreign key constraint "association_child_id_fkey" on "association"

code=0
state=23503


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.