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); } }
|