我正在为数据库应用程序编写 JUnit 测试。针对我的测试 (HSQLDB) 数据库运行测试失败。我想得到的错误消息是这个错误消息,这是实际的异常,我完全理解:
org.hsqldb.HsqlException: Violation of unique constraint SYS_PK_47: duplicate value(s) for column(s) SECONDARY_ACCOUNT_ID
但是,此信息不会出现在测试失败的堆栈跟踪中的任何位置。相反,错误似乎是通过 Spring、Hibernate 和 JDBC 过滤的,我得到了这个完全无用、无信息的“JDBC 异常”:
org.springframework.orm.hibernate3.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [insert into CAACCTS (CREDIT_APPLICATION_ID, PRIMARY_ACCOUNT_NUMBER, SECONDARY_ACCOUNT_ID, SECONDARY_ACCT_NAME, SECONDARY_ADDY_ID, SECONDARY_ACCOUNT_NUMBER) values (?, ?, ?, ?, ?, ?)]; SQL state [null]; error code [0]; Could not execute JDBC batch update; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:651)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.data.jpa.repository.support.LockModeRepositoryPostProcessor$LockModePopulatingMethodIntercceptor.invoke(LockModeRepositoryPostProcessor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy26.save(Unknown Source)
[snip]
我已经将 Log4J 日志设置到 TRACE 没有成功。谁能告诉我如何抓住这个原始错误(不仅在这个失败的测试中,而且在未来的测试中也是如此?)
我正在使用 HSQLDB、Spring 3、Hibernate 3.6 和 JPA 2。我的 IDE 是 Intellij IDEA。该项目是基于 Maven 的。如果需要帮助我诊断此问题,我将很乐意提供更多详细信息。