-->
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.  [ 2 posts ] 
Author Message
 Post subject: OneToMany cascade delete
PostPosted: Sun Jan 13, 2013 1:22 pm 
Newbie

Joined: Sun Jan 13, 2013 1:13 pm
Posts: 1
Hi, i have a association oneToMany

One Corso have many Lezioni. I write:
Code:
public class Corso{
...
@OneToMany(mappedBy="corso")
@Cascade(value={CascadeType.SAVE_UPDATE,CascadeType.DELETE})
private Collection<Lezione> lezione=new ArrayList<Lezione>();
...
}


in class Lezione:
Code:
public class Lezione{
...
@ManyToOne
@JoinColumn(name = "ID_CORSO", nullable = false)
private Corso corso;
...
}


In dao i write:

Code:
getHibernateTemplate().delete(corso);


I tried to cancel a course a Corso, but I get the error:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/project] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations): [org.rol.pojo.Lezione#4]; nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [org.rol.pojo.Lezione#4]] with root cause
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [org.rol.pojo.Lezione#4]


why?
I if I delete a course I want to delete the lessons associated


Top
 Profile  
 
 Post subject: Re: OneToMany cascade delete
PostPosted: Mon Jan 14, 2013 6:03 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi globalace,

seems that in some way after calling

Code:
getHibernateTemplate().delete(corso);


somewhere is called corso.saveOrUpdate(), which should not happen.

Can you please post the whole stacktrace of the exception?
Se we should see in which point saveOrUpdate is called.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.