-->
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: orphan child records not deleting in @OneToMany association
PostPosted: Fri Oct 05, 2007 12:31 am 
Newbie

Joined: Fri Oct 05, 2007 12:02 am
Posts: 3
Hello -
I've got a one-to-many relationship between A and B. For each A, there can be 0 or many Bs. When I add a new B to the list, then call entityManager.merge(A), it works fine. The new B is also persisted in its own table. However, if I manipulate the list of Bs by removing a couple of the B records, then persist A as before, the Bs I removed from the list are not deleted from the B table.

I've tried overriding the "equals" and "hashcode" methods in my entity classes (Eclipse-generated), and have tried several approaches with the annotations, but I just can't get the B records to delete. It looks like maybe I need something like cascade=all, delete-orphan, but I can't find the equivalent to this using annotations. It seems like I'm so close, so maybe there's something easy I'm doing wrong. I'm pretty new to Hibernate, so maybe this is not the way it is supposed to work. Here's the relevant (pseudo)code:

In A:
Code:
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
   @JoinColumn(name="aKey")
   @OrderBy("bDate ASC")
        getter for B
       
        setter for B


In B:
Code:
@ManyToOne
   @JoinColumn(name="aKey")
   getter for A

        setter for A


Any help would be appreciated.


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.