-->
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.  [ 1 post ] 
Author Message
 Post subject: Question: Exception handling
PostPosted: Thu Nov 20, 2014 6:09 am 
Newbie

Joined: Thu Nov 20, 2014 5:33 am
Posts: 1
Problem: I can not catch hibernate exceptions.

By error, I had a duplicate line in hibernate.cfg.xml like this:
<mapping resource="hibernateGenerate/MailAddTbl.hbm.xml" />
<mapping resource="hibernateGenerate/MailAddTbl.hbm.xml" />


On the console I get the correct failure messages:
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource hibernateGenerate/MailAddTbl.hbm.xml
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping de.mycomp.MailAddTbl


So I added a try/catch in my method. But it does not act as it should. Debugger stops for 10 seconds at the line "Session...", then the console messages show up and the method crashes. But it should go into the catch block.
I tried only catching "Expection", also catching the hibernate Exceptions seen in the console.

May be Java's try/catch is unable to catch hibernate's Exceptions?
Any idea what is wrong?


Code:
public List<MailAddLi> readMailAdd() throws Exception {
try {
Session hibsession = HibernateUtil.getSessionFactory().openSession();
Query query = hibsession.createQuery("from
. . .
return list;
} catch (DuplicateMappingException e) {
System.out.println("DuplicateMappingException " + e);
} catch (InvalidMappingException e1) {
System.out.println("InvalidMappingException " + e1);
} catch (Exception e2) {
System.out.println("Exception " + e2);
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.