Hello,
I have a parent - child relationship where I am return the collection of child objects in a MAP. However, when I try to delete the parent object with cascade delete on, it fails. The generated sql shows that for some reason its trying to update the child collections.
Any idea as to what the problem may be?
thanks
Hibernate version:3.2
Mapping documents:
Code:
<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>
<!--
<many-to-one name="metadataType" class="org.openiam.idm.srvc.meta.dto.MetadataType" fetch="select">
<column name="TYPE_ID" length="20">
<comment></comment>
</column>
</many-to-one>
-->
<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>
<property name="title" type="string">
<column name="TITLE" length="30">
<comment></comment>
</column>
</property>
<property name="dept" type="string">
<column name="DEPT" length="20">
<comment></comment>
</column>
</property>
<property name="status" type="string">
<column name="STATUS" length="20">
<comment></comment>
</column>
</property>
<property name="birthdate" type="timestamp">
<column name="BIRTHDATE" length="19">
<comment></comment>
</column>
</property>
<property name="sex" type="java.lang.Character">
<column name="SEX" length="1">
<comment></comment>
</column>
</property>
<property name="createDate" type="timestamp">
<column name="CREATE_DATE" length="19">
<comment></comment>
</column>
</property>
<property name="createdBy" type="string">
<column name="CREATED_BY" length="20">
<comment></comment>
</column>
</property>
<property name="lastUpdate" type="timestamp">
<column name="LAST_UPDATE" length="19">
<comment></comment>
</column>
</property>
<property name="lastUpdatedBy" type="string">
<column name="LAST_UPDATED_BY" length="20">
<comment></comment>
</column>
</property>
<property name="prefix" type="string">
<column name="PREFIX" length="4">
<comment></comment>
</column>
</property>
<property name="suffix" type="string">
<column name="SUFFIX" length="20">
<comment></comment>
</column>
</property>
<property name="userTypeInd" type="string">
<column name="USER_TYPE_IND" length="20">
<comment></comment>
</column>
</property>
<property name="employeeId" type="string">
<column name="EMPLOYEE_ID" length="20">
<comment></comment>
</column>
</property>
<property name="employeeType" type="string">
<column name="EMPLOYEE_TYPE" length="20">
<comment></comment>
</column>
</property>
<property name="locationId" type="string">
<column name="LOCATION_ID" length="20">
<comment></comment>
</column>
</property>
<property name="companyId" type="string">
<column name="COMPANY_ID" length="20">
<comment></comment>
</column>
</property>
<property name="companyOwnerId" type="string">
<column name="COMPANY_OWNER_ID" length="20">
<comment></comment>
</column>
</property>
<property name="expirationDate" type="timestamp">
<column name="EXPIRATION_DATE" length="19">
<comment></comment>
</column>
</property>
<property name="managerId" type="string">
<column name="MANAGER_ID" length="20">
<comment></comment>
</column>
</property>
<property name="jobCode" type="string">
<column name="JOB_CODE" length="20">
<comment></comment>
</column>
</property>
<map name="userAttributes" cascade="all" inverse="false" >
<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>
Code:
<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>
<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 between sessionFactory.openSession() and session.close():
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$$1fc56c2.removeUser(<generated>)
at org.openiam.idm.srvc.user.UserMgrTest.testRemoveUserWithChildren(UserMgrTest.java:126)
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)
Name and version of the database you are using: MySQL
The generated SQL (show_sql=true):
Hibernate: select user_.USER_ID, user_.FIRST_NAME as FIRST2_130_, user_.LAST_NAME as LAST3_130_, user_.MIDDLE_INIT as MIDDLE4_130_, user_.TITLE as TITLE130_, user_.DEPT as DEPT130_, user_.STATUS as STATUS130_, user_.BIRTHDATE as BIRTHDATE130_, user_.SEX as SEX130_, user_.CREATE_DATE as CREATE10_130_, user_.CREATED_BY as CREATED11_130_, user_.LAST_UPDATE as LAST12_130_, user_.LAST_UPDATED_BY as LAST13_130_, user_.PREFIX as PREFIX130_, user_.SUFFIX as SUFFIX130_, user_.USER_TYPE_IND as USER16_130_, user_.EMPLOYEE_ID as EMPLOYEE17_130_, user_.EMPLOYEE_TYPE as EMPLOYEE18_130_, user_.LOCATION_ID as LOCATION19_130_, user_.COMPANY_ID as COMPANY20_130_, user_.COMPANY_OWNER_ID as COMPANY21_130_, user_.EXPIRATION_DATE as EXPIRATION22_130_, user_.MANAGER_ID as MANAGER23_130_, user_.JOB_CODE as JOB24_130_ from USERS user_ where user_.USER_ID=?
Hibernate: update user_attributes set USER_ID=null, ID=null where USER_ID=?