-->
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: CascadeType.ALL and DELETE_ORPHAN doesnt work
PostPosted: Fri Jun 16, 2006 11:18 am 
Newbie

Joined: Fri Jun 16, 2006 11:06 am
Posts: 1
I have the following one to many bidirectional relationship defined.


@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "journal")
@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@OrderBy(value = "sequence")
public List<JournalLine> getJournalLines() {
return this.journalLines;
}


If i execute the following:
beginTransaction();
Journal found = DAOFactory.DEFAULT.getJournalDAO().findById(new Long(187007),false);
found.getJournalLines().clear();
found.setJournalStatus(JournalStatus.DELTED);
endTransaction();

It fails with:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.catlin.da.insuranceledger.model.JournalLine#5]

If i drop the last line:
beginTransaction();
Journal found = DAOFactory.DEFAULT.getJournalDAO().findById(new Long(187007),false);
found.getJournalLines().clear();
// found.setJournalStatus(JournalStatus.DELTED);
endTransaction();

It works

Or if I drop the DELETE_ORPHAN it also works?

It seems that setting CascadeType.ALL in fact are deleting children by just clearing the collection. No need to explicitly deleting the children!!! In other words the DELETE_ORPHAN is not nessesary????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 1:25 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I think what is happening is that hibernate can not persist the changes (when you clear the collection) to the database and when you try to setStatus(deleted) it errors because the object is not in sync with the database.

check the logs and see if any sql is being run when you call found.getJournalLines().clear();

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.