Hello all,

I've got a problem with the update of a manyToOne field which is mapped by another entity. I searched and tried out for the last week and I didn't had success, so I ask here. BTW, I'm new to JPA so maybe it's a conceptual problem.

My test case is fairly simple. I've got to entities A and B.

A has got a ManyToOne relationship to B.
B has got a OneToMany rel to A.

--- entity A ---
@Entity
public class A {
   @ManyToOne(cascade = CascadeType.ALL)
   @JoinColumn(name = "BID", referencedColumnName = "ID")
   private B b;
//...
---

--- entity B ---
@Entity
public class B {
@OneToMany(mappedBy = "b", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
   private Collection<A> as;
//...
---

What I want is the following: When I update the field 'b' of an A (lets say a6.setB(b5)) and I call the b5.getAs(), I would like to get a list including the a6. But the Collection 'as' of b5 hasn't been updated.

I tried the following as assignment:

---
public String actionA6SetB5() {
       a6.setB(b5);
       dataManager.getEm().persist(a6);
         return null;
   }

I also tried:

---
public String actionA6SetB5() {
       dataManager.getEm().getTransaction().begin();
       a6.setB(b5);
       dataManager.getEm().persist(a6);
       dataManager.getEm().flush();
       dataManager.getEm().getTransaction().commit();

       return null;
   }

How can I achieve that the OneToMany rel would be also updated?

Thanks and greetings,
Stefan

PS: I use openJPA 1.2.0 and new, 1.2.1

Reply via email to