I am using hibernate with Spring. My problem is that the exceptions thrown by the JDBC driver are not correct interpreted by Spring (at least not as I see it) .
For example: if i got a FK constraint from the database, Spring throws
org.springframework.orm.hibernate.HibernateJdbcException which is a subclass of UncategorizedDataAccessException .
I was expected a DataIntegrityViolationException instead.
Do I missunderstand the meaning of Spring interpreting the exception?
Or maybe a configuration problem?
I must mention that I got the same problem using Mysql InnoDB and MSSQL.
This is an excerpt of the output the running method generates:
INFO: Creating new JDBC connection to [jdbc:JSQLConnect://192.168.1.21/database=webmin] Mar 4, 2004 12:35:23 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions WARNING: SQL Error: 547, SQLState: 23000 Mar 4, 2004 12:35:23 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK5AE5775538A56BFB'. The conflict occurred in database 'webmin', table 'menu', column 'id'. Mar 4, 2004 12:35:23 PM net.sf.hibernate.JDBCException <init> SEVERE: Could not insert com.jnetdirect.jsql.u: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK5AE5775538A56BFB'. The conflict occurred in database 'webmin', table 'menu', column 'id'. at com.jnetdirect.jsql.aq.a(Unknown Source) at com.jnetdirect.jsql.ae.f(Unknown Source) at com.jnetdirect.jsql.ae.int(Unknown Source) at com.jnetdirect.jsql.ae.new(Unknown Source) at com.jnetdirect.jsql.ak.executeUpdate(Unknown Source) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504) at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444) at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:717) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605) at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202) at org.springframework.orm.hibernate.HibernateTemplate$2.doInHibernate(HibernateTemplate.java:220) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:144) at org.springframework.orm.hibernate.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:218) at ro.gebs.webmin.dao.hibernate.MenuOptionDAOImpl.saveMenuOption(MenuOptionDAOImpl.java:134) at ro.gebs.webmin.service.hibernate.AdminServiceImpl.saveMenuOption(AdminServiceImpl.java:189) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.springframework.aop.interceptor.AbstractReflectionInvokerInterceptor.invoke(AbstractReflectionInvokerInterceptor.java:54) at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:152) at org.springframework.aop.framework.MethodInvocationImpl.proceed(MethodInvocationImpl.java:216) at org.springframework.aop.framework.AopProxy.invoke(AopProxy.java:102) at $Proxy0.saveMenuOption(Unknown Source) at ro.gebs.webmin.unittests.ExceptionTest.testForeignKeyException(ExceptionTest.java:148) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at junit.textui.TestRunner.doRun(TestRunner.java:116) at junit.textui.TestRunner.start(TestRunner.java:172) at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12) Mar 4, 2004 12:35:23 PM org.springframework.transaction.interceptor.TransactionInterceptor onThrowable SEVERE: Rolling back transaction on method 'saveMenuOption' due to throwable: JDBC exception on Hibernate data access: Could not insert: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK5AE5775538A56BFB'. The conflict occurred in database 'webmin', table 'menu', column 'id'.; nested exception is: com.jnetdirect.jsql.u: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK5AE5775538A56BFB'. The conflict occurred in database 'webmin', table 'menu', column 'id'.
|