-->
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: Unable to delete child when parent is deleted
PostPosted: Wed Jan 07, 2009 9:17 am 
Newbie

Joined: Wed Jan 07, 2009 9:07 am
Posts: 3
Location: India
Hi,
i m a newbie....so forgive me for any mistakes
i have a bidirectional relationship
here is the code for my parent entity with child set

<set name="children" lazy="false" inverse="true"
cascade="all-delete-orphan">
<key column="PARENT_ID" on-delete="cascade" />
<one-to-many class="com.java.Child" />
</set>

here is the code for child enttity

<many-to-one name="parent" class="com.java.Parent" lazy="false">
<column name="PARENT_ID" precision="10" scale="0" not-null="true"/>
</many-to-one>

however when i try to delete a parent having a children i get the following exception. Please help......


WARNING: SQL Error: 2292, SQLState: 23000
Jan 7, 2009 6:34:43 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-02292: integrity constraint (TRIAL_DB.FKEF345F49DSAF23EAD) violated - child record found

Jan 7, 2009 6:34:43 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 2292, SQLState: 23000
Jan 7, 2009 6:34:43 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-02292: integrity constraint (TRIAL_DB.FKEF345F49DSAF23EAD) violated - child record found

Jan 7, 2009 6:34:43 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
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:249)
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.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:394)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:766)
at org.springframework.orm.hibernate3.HibernateTemplate.delete(HibernateTemplate.java:762)
at com.infosys.knowledgeBase.DAO.CategoryDAO.delete(CategoryDAO.java:44)
at com.infosys.knowledgeBase.serviceManager.CategoryServiceManagerImpl.deleteCategory(CategoryServiceManagerImpl.java:31)
at com.infosys.knowledgeBase.action.CategoryAction.deleteCategory(CategoryAction.java:201)
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 com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:434)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:273)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:235)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:141)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:248)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:49)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:124)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:456)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:227)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:170)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:230)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:229)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 10:41 am 
Beginner
Beginner

Joined: Wed Nov 26, 2008 1:02 am
Posts: 22
Hi,

Use cascade="all" instead of all-delete-orphan because you are deleting parent so child is not an orphan at that time,all-delete-orphan is used for deleting childs which are orphans.

regards

_________________
if it solves,rate me


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 11:11 pm 
Newbie

Joined: Wed Jan 07, 2009 9:07 am
Posts: 3
Location: India
AKumar1 wrote:
Hi,

Use cascade="all" instead of all-delete-orphan because you are deleting parent so child is not an orphan at that time,all-delete-orphan is used for deleting childs which are orphans.

regards



Nope ..:(
i am still getting the same foreign key exception....


Top
 Profile  
 
 Post subject: hi
PostPosted: Thu Jan 08, 2009 2:51 am 
Beginner
Beginner

Joined: Wed Nov 26, 2008 1:02 am
Posts: 22
observe this,<column name="PARENT_ID" precision="10" scale="0" not-null="true"/> you are giving parent column should be not null(not-null="true"),but when you are deleting the column should be null.
check this,

regards

_________________
if it solves,rate me


Top
 Profile  
 
 Post subject: finally got it
PostPosted: Thu Jan 08, 2009 3:18 am 
Newbie

Joined: Wed Jan 07, 2009 9:07 am
Posts: 3
Location: India
hi,
thanks for the help...
i figured it out...
i removed the "on-delete=cascade" from the key column of the child set and it solved the problem

<key column="PARENT_ID" />


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.