-->
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: Problem with oneToMany relations...
PostPosted: Thu May 11, 2006 6:34 pm 
Newbie

Joined: Thu May 11, 2006 6:25 pm
Posts: 2
Hibernate version: 3.1

Hi people,

I´m having a problem with oneToMany associations... For example, The entity A have a list of entity B, when i insert a new element of B and update A everything goes clear... when i update a element of the list B and update A everything goes clear... but when i delete a element of the list B and update A.. nothing happens.. the hibernate just update the other elements but don´t delete the others... here a example of the mapping..
Code:
Class A {
    Set<B> bs;
    @OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL,    mappedBy ="a" )
    public Set getB();
}

Class B {
     A a;
     @ManyToOne
     @JoinColumn(name = "OID_A")
     public A getA();

}

Please... help me... I tried to manipulate the PersistentSet directly.. but when i do this a exception is throw "Found two representations of the collection". I Tried ALL_DELETE_ORPHAN.. I Tried everything....


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 6:48 pm 
Newbie

Joined: Wed Nov 23, 2005 5:01 am
Posts: 15
Hi ,

For bidirectional associations you have to specify "inverse=true" into the one side. For example if you have A that have a list of B and B has a many-to-one relation with A than you have to specifie into A mapping the following:
<set name="setOfB" cascade="all-delete-orphan" inverse="true">
.....
</set>


And you have also to specify all-delete-orphan if you want to delete an instance of B from the A set and in the same time the B instance to be deleted from database.

_________________
I hope this help.
Calin


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 11:35 am 
Newbie

Joined: Thu May 11, 2006 6:25 pm
Posts: 2
But how you do this with annotations??? I think with the property maped by i have this behavior...


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.