From 3ce6fd31485faf5fd18c029c3c8db63be3634784 Mon Sep 17 00:00:00 2001 From: Colby Litnak Date: Thu, 20 Nov 2014 14:09:04 -0700 Subject: [PATCH 1/2] attempt to show nested hibernate exceptions --- .../railo/runtime/orm/hibernate/CommonUtil.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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..8af7056d57 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 @@ -296,18 +296,13 @@ public static Array toArray(Argument arg) { } public static PageException toPageException(Throwable t) { - if (!(t instanceof JDBCException)) + if (!(t instanceof org.hibernate.HibernateException)) return caster().toPageException(t); - - - JDBCException j = (JDBCException)t; - String message = j.getMessage(); - Throwable cause = j.getCause(); - if(cause != null) { - message += " [" + cause.getMessage() + "]"; - } - return CFMLEngineFactory.getInstance().getExceptionUtil().createDatabaseException(message, new SQLImpl(j.getSQL())); - + org.hibernate.HibernateException he = (org.hibernate.HibernateException)t; + Throwable cause = he.getCause(); + if(cause == null) + return caster().toPageException(t); + return caster().toPageException( cause ); } public static Serializable toSerializable(Object obj) throws PageException { return caster().toSerializable(obj); From 07c6cb3e0dfcd3c5034c9a9a79d631462cc05a76 Mon Sep 17 00:00:00 2001 From: Colby Litnak Date: Thu, 20 Nov 2014 15:35:07 -0700 Subject: [PATCH 2/2] https://issues.jboss.org/browse/RAILO-3259 --- .../runtime/orm/hibernate/CommonUtil.java | 29 ++++++++++++++----- .../orm/hibernate/HibernateORMSession.java | 7 ----- 2 files changed, 22 insertions(+), 14 deletions(-) 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 8af7056d57..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,13 +298,26 @@ public static Array toArray(Argument arg) { } public static PageException toPageException(Throwable t) { - if (!(t instanceof org.hibernate.HibernateException)) - return caster().toPageException(t); - org.hibernate.HibernateException he = (org.hibernate.HibernateException)t; - Throwable cause = he.getCause(); - if(cause == null) - return caster().toPageException(t); - return caster().toPageException( cause ); + 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 ); + } + } + 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); }