Skip to content

Commit 86934e2

Browse files
committed
added SQL String and related context to translated JDBCException messages (SPR-6304)
1 parent 747300f commit 86934e2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -625,16 +625,21 @@ public static DataAccessException convertHibernateAccessException(HibernateExcep
625625
return new DataAccessResourceFailureException(ex.getMessage(), ex);
626626
}
627627
if (ex instanceof SQLGrammarException) {
628-
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
628+
SQLGrammarException jdbcEx = (SQLGrammarException) ex;
629+
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
629630
}
630631
if (ex instanceof LockAcquisitionException) {
631-
return new CannotAcquireLockException(ex.getMessage(), ex);
632+
LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
633+
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
632634
}
633635
if (ex instanceof ConstraintViolationException) {
634-
return new DataIntegrityViolationException(ex.getMessage(), ex);
636+
ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
637+
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() +
638+
"]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
635639
}
636640
if (ex instanceof DataException) {
637-
return new DataIntegrityViolationException(ex.getMessage(), ex);
641+
DataException jdbcEx = (DataException) ex;
642+
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
638643
}
639644
if (ex instanceof JDBCException) {
640645
return new HibernateJdbcException((JDBCException) ex);

0 commit comments

Comments
 (0)