我有使用 Hibernate (3.6.9.Final) 的 Spring MVC (3.1.1.RELEASE) 应用程序。它配置了 Log4j。
log4j.category.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=OFF
当我尝试在表中添加一行时,如果字段的长度超过最大大小,在日志中我可以看到这个异常:
hibernateTemplate.merge(ba);
在日志中:
2012-07-06 15:22:35,546 ERROR [org.hibernate.util.JDBCExceptionReporter] - <ERROR: value `too long for type character varying(70)>`
但另一方面,在我的代码中,我只能捕捉到这个DataAccessException异常:
Could not execute JDBC batch update; SQL [insert into T_MYTABLE (BA_NUMBER, USR_ID, BA_ID) values (?, ?, ?)]; nested exception is org.hibernate.exception.DataException: Could not execute JDBC batch update"}
这不是我想要的例外。
您知道如何在我的应用程序中从日志文件中获取消息吗?
我试过捕捉HibernateException但没有成功。