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.  [ 1 post ] 
Author Message
 Post subject: cascade causes double deletion?
PostPosted: Mon Apr 05, 2010 12:11 pm 
Newbie

Joined: Wed Aug 12, 2009 1:46 pm
Posts: 7
setup: spring 2.5.6 + Hibernate 3.1 (annotation driven) + Oracle 11g

problem: I am seeing the same object being deleted twice from within one of my DAO methods. This causes the connection deadlock due to next row locking (until oracle figures out the current connection already owns the lock) , since the first deletion took out a lock on the deleted row.
SQL: delete from DerivationPath where id = 3 and optlock = 1
...
SQL: delete from DerivationPath where id = 3 and optlock = 1

I believe that a cascade of delete_orphan is the cause. I'm trying to understand exactly how this is happening. Is this expected behavior for hibernate or is my
annotations somehow wrong?

Here is a simplified domain model -- a person has a set of documents (a set of documents which can be derived from other documents). Note the DerivationPath is always a directed acyclic graph. The deadlock does not always occur, it seems to depends on the object graph; in particular, this case causes double delete:
Code:
[Document 1]-- \
                  + [DerivationPath]--- [Document 3]
[Document 2] --/

Test case:
Code:
Person p = getHibernateTemplate.loadById(id, Person.class);
getHibernateTemplate.delete(P);
...

Domain model:
Code:
class Person {
  @OneToMany(mappedBy = "personBackRef", cascade = { CascadeType.ALL })  // JPA annotation
  @Cascade( { SAVE_UPDATE }) // Hibernate annotation
  public List<Document > getDocuments() {
}

class Document {
  @OneToOne // JPA
  @Cascade( { SAVE_UPDATE, DELETE_ORPHAN }) // hibernate
  public DerivationPath getDerivationPath();
}

class DerivationPath {
  @OneToMany // JPA
  List<Document> getSource();
}


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

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.