These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Cascasde Delete Does not work
PostPosted: Sun Jun 17, 2007 9:56 am 
Beginner
Beginner

Joined: Mon May 07, 2007 11:12 pm
Posts: 20
Hello,

I have a one to many relationship and the cascade delete feature is not working. Looking at the generated sql, the problem seems to be that the sql to delete child objects is not be generated. Any thoughts on how I can resolve this?

Hibernate version:3.2

[b]Mapping documents:


<class name="org.openiam.idm.srvc.service.dto.Service" table="SERVICE" >
<comment></comment>
<id name="serviceId" type="string">
<column name="SERVICE_ID" length="20" />
<generator class="assigned" />
</id>
<property name="serviceName" type="string">
<column name="SERVICE_NAME" length="40">
<comment></comment>
</column>
</property>
<property name="status" type="string">
<column name="STATUS" length="20">
<comment></comment>
</column>
</property>
<property name="serviceType" type="string">
<column name="SERVICE_TYPE" length="20">
<comment></comment>
</column>
</property>
<property name="parentServiceId" type="string">
<column name="PARENT_SERVICE_ID" length="20">
<comment></comment>
</column>
</property>
<set name="serviceConfigs" inverse="true" cascade="all-delete-orphan">
<key>
<column name="SERVICE_ID" length="20">
<comment></comment>
</column>
</key>
<one-to-many class="org.openiam.idm.srvc.service.dto.ServiceConfig" />
</set>

</class>
</hibernate-mapping>


<hibernate-mapping default-lazy="false">
<class name="org.openiam.idm.srvc.service.dto.ServiceConfig" table="service_config">
<comment></comment>
<id name="serviceConfigId" type="string">
<column name="SERVICE_CONFIG_ID" length="20" />
<generator class="assigned" />
</id>
<many-to-one name="service" class="org.openiam.idm.srvc.service.dto.Service"
fetch="select">
<column name="SERVICE_ID" length="20">
<comment></comment>
</column>
</many-to-one>
<property name="name" type="string">
<column name="NAME" length="40">
<comment></comment>
</column>
</property>
<property name="value" type="string">
<column name="VALUE" length="40">
<comment></comment>
</column>
</property>
</class>
</hibernate-mapping>


Full stack trace of any exception that occurs:

org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
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.service.service.ServiceMgr$$EnhancerByCGLIB$$45610be2.removeService(<generated>)
at org.openiam.idm.srvc.service.ServiceMgrTest.testRemoveServiceWithAssociation(ServiceMgrTest.java:164)
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)
Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`mysql/service_config`, CONSTRAINT `FK_SRV_SRV_CONF` FOREIGN KEY (`SERVICE_ID`) REFERENCES `service` (`SERVICE_ID`))
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)
... 36 more



Name and version of the database you are using: MySQL

The generated SQL (show_sql=true):

Hibernate: select service_.SERVICE_ID, service_.SERVICE_NAME as SERVICE2_154_, service_.STATUS as STATUS154_, service_.LOCATION_IP_ADDRESS as LOCATION4_154_, service_.COMPANY_OWNER_ID as COMPANY5_154_, service_.START_DATE as START6_154_, service_.END_DATE as END7_154_, service_.LICENSE_KEY as LICENSE8_154_, service_.SERVICE_TYPE as SERVICE9_154_, service_.PARENT_SERVICE_ID as PARENT10_154_, service_.ROOT_RESOURCE_ID as ROOT11_154_, service_.ACCESS_CONTROL_MODEL as ACCESS12_154_, service_.PARAM1 as PARAM13_154_, service_.PARAM2 as PARAM14_154_, service_.PARAM3 as PARAM15_154_, service_.PARAM4 as PARAM16_154_, service_.PARAM5 as PARAM17_154_ from SERVICE service_ where service_.SERVICE_ID=?
Hibernate: delete from SERVICE where SERVICE_ID=?


DAO Code:

public void delete(Service persistentInstance) {
log.debug("deleting Service instance");
try {
sessionFactory.getCurrentSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sun Jun 17, 2007 4:35 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
try removing inverse=true?

Inverse = true give the control of reference manipulation to the child class, so the delete-orphan cascade may not work.

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 17, 2007 4:46 pm 
Beginner
Beginner

Joined: Mon May 07, 2007 11:12 pm
Posts: 20
Thanks very much. That worked.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Mon Jun 18, 2007 1:51 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Good to know that :-)

Please give appropriate credit.

Regards,
Jitendra


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Jun 29, 2007 5:52 pm 
Newbie

Joined: Fri Jun 29, 2007 5:48 pm
Posts: 1
jits_1998 wrote:
try removing inverse=true?

Inverse = true give the control of reference manipulation to the child class, so the delete-orphan cascade may not work.

Regards,
Jitendra


I have the same issue, but can't get rid of the inverse relationship. Any other suggestions?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.