From 86934e2403126661c266fd7fd52103b4e942a06c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 12 Nov 2009 15:25:32 +0000 Subject: [PATCH] added SQL String and related context to translated JDBCException messages (SPR-6304) --- .../orm/hibernate3/SessionFactoryUtils.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java index 396e46f112..f269c00710 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -625,16 +625,21 @@ public abstract class SessionFactoryUtils { return new DataAccessResourceFailureException(ex.getMessage(), ex); } if (ex instanceof SQLGrammarException) { - return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex); + SQLGrammarException jdbcEx = (SQLGrammarException) ex; + return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof LockAcquisitionException) { - return new CannotAcquireLockException(ex.getMessage(), ex); + LockAcquisitionException jdbcEx = (LockAcquisitionException) ex; + return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof ConstraintViolationException) { - return new DataIntegrityViolationException(ex.getMessage(), ex); + ConstraintViolationException jdbcEx = (ConstraintViolationException) ex; + return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex); } if (ex instanceof DataException) { - return new DataIntegrityViolationException(ex.getMessage(), ex); + DataException jdbcEx = (DataException) ex; + return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex); } if (ex instanceof JDBCException) { return new HibernateJdbcException((JDBCException) ex);