-->
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.  [ 3 posts ] 
Author Message
 Post subject: CascadeType.DELETE_ORPHAN broken?
PostPosted: Sat Aug 20, 2005 3:53 pm 
Beginner
Beginner

Joined: Mon May 16, 2005 6:06 am
Posts: 20
Hi,
I'm trying to use Hibernate's "delete orphan" feature and it keeps failing in my application. Objects that I removed from the parent's child collection are not deleted when persisting the parent object.

Therefore I checked the hibernate source code for similiar tests and found a test in the Hibernate Annotation package org.hibernate.test.annotations.onetomany.OneToMany.testCascadeDeleteOrphan(). I changed this test so that it uses the EntityManager instead of the HibernateSession and it is now failing too.

Here is the code I tried:
Code:
public void testCascadeDeleteOrphan() throws Exception
{
   EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");
   EntityTransaction tx;

   EntityManager em = emf.createEntityManager();
   tx = em.getTransaction();
   tx.begin();
   Troop disney = new Troop();
   disney.setName("Disney");
   Soldier mickey = new Soldier();
   mickey.setName("Mickey");
   disney.addSoldier(mickey);
   em.persist(disney);
   tx.commit();
   em.close();

   em = emf.createEntityManager();
   tx = em.getTransaction();
   tx.begin();
   Troop troop = em.find(Troop.class, disney.getId());
   Soldier soldier = troop.getSoldiers().iterator().next();
   troop.getSoldiers().remove(soldier);
   tx.commit();
   em.close();

   em = emf.createEntityManager();
   tx = em.getTransaction();
   tx.begin();
   soldier = em.find(Soldier.class, mickey.getId());
   assertNull("delete-orphan should work", soldier);
   troop = em.find(Troop.class, disney.getId());
   em.remove(troop);
   tx.commit();
   em.close();
}


Ideas and comments are welcome.

Regards,
Johan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 21, 2005 8:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thanks for pointing this out. I've fixed the bug

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 4:17 am 
Beginner
Beginner

Joined: Mon May 16, 2005 6:06 am
Posts: 20
hi Emmanuel,

no problem. Thanks for fixing it!

Johan


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