diff --git a/railo-java/railo-core/src/railo/runtime/orm/hibernate/CommonUtil.java b/railo-java/railo-core/src/railo/runtime/orm/hibernate/CommonUtil.java index d8c57a8bd6..255b7e53d7 100644 --- a/railo-java/railo-core/src/railo/runtime/orm/hibernate/CommonUtil.java +++ b/railo-java/railo-core/src/railo/runtime/orm/hibernate/CommonUtil.java @@ -22,6 +22,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.hibernate.JDBCException; +import org.hibernate.exception.ConstraintViolationException; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.SAXException; @@ -29,6 +30,7 @@ import railo.commons.io.res.Resource; import railo.commons.lang.types.RefBoolean; import railo.loader.engine.CFMLEngineFactory; +import railo.loader.util.Util; import railo.runtime.Component; import railo.runtime.MappingImpl; import railo.runtime.PageContext; @@ -296,18 +298,26 @@ public static Array toArray(Argument arg) { } public static PageException toPageException(Throwable t) { - if (!(t instanceof JDBCException)) - return caster().toPageException(t); - - - JDBCException j = (JDBCException)t; - String message = j.getMessage(); - Throwable cause = j.getCause(); - if(cause != null) { - message += " [" + cause.getMessage() + "]"; + PageException pe = caster().toPageException(t);; + if (t instanceof org.hibernate.HibernateException) { + org.hibernate.HibernateException he = (org.hibernate.HibernateException)t; + Throwable cause = he.getCause(); + if(cause != null) { + pe = caster().toPageException( cause ); + ExceptionUtil.setAdditional(pe, CommonUtil.createKey("hibernate exception"), t ); + } } - return CFMLEngineFactory.getInstance().getExceptionUtil().createDatabaseException(message, new SQLImpl(j.getSQL())); - + if ( t instanceof JDBCException ) { + JDBCException je = (JDBCException)t; + ExceptionUtil.setAdditional(pe, CommonUtil.createKey("sql"), je.getSQL()); + } + if( t instanceof ConstraintViolationException) { + ConstraintViolationException cve = (ConstraintViolationException)t; + if(!Util.isEmpty(cve.getConstraintName())) { + ExceptionUtil.setAdditional(pe, CommonUtil.createKey("constraint name"), cve.getConstraintName()); + } + } + return pe; } public static Serializable toSerializable(Object obj) throws PageException { return caster().toSerializable(obj); diff --git a/railo-java/railo-core/src/railo/runtime/orm/hibernate/HibernateORMSession.java b/railo-java/railo-core/src/railo/runtime/orm/hibernate/HibernateORMSession.java index 07ad50715d..a097207cd8 100755 --- a/railo-java/railo-core/src/railo/runtime/orm/hibernate/HibernateORMSession.java +++ b/railo-java/railo-core/src/railo/runtime/orm/hibernate/HibernateORMSession.java @@ -84,13 +84,6 @@ public void flush(PageContext pc) throws PageException { try { session().flush(); } - catch(ConstraintViolationException cve){ - PageException pe = ExceptionUtil.createException(this,null,cve); - if(!Util.isEmpty(cve.getConstraintName())) { - ExceptionUtil.setAdditional(pe, CommonUtil.createKey("constraint name"), cve.getConstraintName()); - } - throw pe; - } catch(Throwable t) { throw CommonUtil.toPageException(t); }