我有使用Hibernate(3.6.9.Final)的Spring MVC(3.1.1.RELEASE)应用程序。 其配置了Log4j。无法捕捉Spring MVC中的org.hibernate.util.JDBCExceptionReporter异常
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但没有成功。
您是否尝试过检查DataAccessException上的exception.getCause()? – Manish 2012-07-06 08:27:04
我刚刚尝试过使用getCause(),但我刚刚得到这个:“无法执行JDBC批量更新不能执行JDBC批量更新”}“ – guigui42 2012-07-06 08:38:45
嗨guigui42,您是否设法捕获JDBCExceptionReporter记录的异常。提交批处理uupdates。我面临类似的问题。 – 2016-01-19 09:55:20