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.MetadataElement" 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(persistentInstance);
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.executeBatch(ServerPreparedStatement.java:665)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:575)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:630)
at org.openiam.idm.srvc.user.service.UserMgr$$EnhancerByCGLIB$$fe8f55ba.removeUser(<generated>)
at org.openiam.idm.srvc.user.UserMgrTest.testRemoveUserWithChildren(UserMgrTest.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown 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.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java: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:228)
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.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
|