-
Jun 19th, 2007, 11:33 PM
#1
Cascasde Delete in Hibernate does not work
Hello,
I have a object called user that has child objects called UserAttributes which are returned as a Map. When, I try to delete a user, I get the exception below. I would like to delete the attributes with the user. Any thoughts on how I can resolve this?
Hibernate version:3.2
Mapping documents:
<hibernate-mapping>
<class name="org.openiam.idm.srvc.user.dto.User" table="USERS" >
<comment></comment>
<id name="userId" type="string">
<column name="USER_ID" length="20" />
<generator class="assigned" />
</id>
<property name="firstName" type="string">
<column name="FIRST_NAME" length="40">
<comment></comment>
</column>
</property>
<property name="lastName" type="string">
<column name="LAST_NAME" length="40">
<comment></comment>
</column>
</property>
<property name="middleInit" type="java.lang.Character">
<column name="MIDDLE_INIT" length="1">
<comment></comment>
</column>
</property>
<map name="userAttributes" cascade="all-delete-orphan">
<key>
<column name="USER_ID" length="20" />
</key>
<map-key column="ID" type="string" />
<one-to-many class="org.openiam.idm.srvc.user.dto.UserAttribute " />
</map>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="org.openiam.idm.srvc.user.dto.UserAttribute" table="user_attributes">
<comment></comment>
<id name="id" type="string">
<column name="ID" length="20" />
<generator class="assigned" />
</id>
<many-to-one name="users" class="org.openiam.idm.srvc.user.dto.User" fetch="select">
<column name="USER_ID" length="20">
<comment></comment>
</column>
</many-to-one>
<!--
<many-to-one name="metadataElement" class="org.openiam.idm.srvc.meta.dto.MetadataEleme nt" fetch="select">
<column name="METADATA_ID" length="20">
<comment></comment>
</column>
</many-to-one>
-->
<property name="name" type="string">
<column name="NAME" length="20">
<comment></comment>
</column>
</property>
<property name="value" type="string">
<column name="VALUE">
<comment></comment>
</column>
</property>
</class>
</hibernate-mapping>
Code:
public void removeUser(String id) {
if (id == null)
throw new NullPointerException("user id is null");
User user = new User(id);
userDao.delete(user);
}
DAO code:
public void delete(User persistentInstance) {
log.debug("deleting User instance");
try {
sessionFactory.getCurrentSession().delete(persiste ntInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
Full stack trace of any exception that occurs:
org.springframework.jdbc.UncategorizedSQLException : Hibernate flushing: Could not execute JDBC batch update; uncategorized SQLException for SQL [update user_attributes set USER_ID=null, ID=null where USER_ID=?]; SQL state [01004]; error code [0]; Data truncation: Column was set to data type implicit default; NULL supplied for NOT NULL column 'ID' at row 1; nested exception is java.sql.BatchUpdateException: Data truncation: Column was set to data type implicit default; NULL supplied for NOT NULL column 'ID' at row 1
Caused by: java.sql.BatchUpdateException: Data truncation: Column was set to data type implicit default; NULL supplied for NOT NULL column 'ID' at row 1
at com.mysql.jdbc.ServerPreparedStatement.executeBatc h(ServerPreparedStatement.java:665)
at org.apache.commons.dbcp.DelegatingPreparedStatemen t.executeBatch(DelegatingPreparedStatement.java:23 1)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch( BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(Ab stractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:298)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:1000)
at org.hibernate.impl.SessionImpl.managedFlush(Sessio nImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doCommit(HibernateTransactionManager. java:575)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:662)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:632)
at org.springframework.transaction.interceptor.Transa ctionAspectSupport.commitTransactionAfterReturning (TransactionAspectSupport.java:314)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:117)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :161)
at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:630)
at org.openiam.idm.srvc.user.service.UserMgr$$Enhance rByCGLIB$$fe8f55ba.removeUser(<generated>)
at org.openiam.idm.srvc.user.UserMgrTest.testRemoveUs erWithChildren(UserMgrTest.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:164 )
at junit.framework.TestCase.runBare(TestCase.java:130 )
at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.ja va:110)
at junit.framework.TestResult.runProtected(TestResult .java:128)
at junit.framework.TestResult.run(TestResult.java:113 )
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:2 28)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run( OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:196)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules