The correct way to remove an item from the OneToMany relation is as follows:
| @Entity
| public class A
| {
| private Collection<B> bees;
| @OneToMany (mappedBy="a")
| public Collection<B> getBs()
| {
| return bees;
| }
| public void setBs(Collection<B> b)
| {
| this. bees = b;
| }}
|
| @Entity
| public class B
| {
| private A a;
| @ManyToOne
| public A getA()
| {
| return a;
| }
| public void setContact(A a)
| {
| this.a = a;
| }}
|
The remove method will look like this in SLSB or SFSB
|
| public void removeAllB(){
| for(B b1: a.getBs()){
| b1.setContact(null);
| }
| manager.merge(a);
| }
|
Please note in EJB3 the merge method will mark A with null in column for a.
This will not remove the record from the database. This must be done using
other hibernate specific tags like DELETE_ORPHAN in OneToMany relations or
through other techniques.
Murtuza
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3995847#3995847
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3995847
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user