java - Hibernate merge issue with one to one mapping -


I have a class hierarchy mapped with the retirements. Janine in Hibernate (3.5.6 Final) with JAP 2.0 -

  @ Entry @ Inheritance (strategy = inheritance type. Jind) Public abstract class A {Private Long ID; @OneToOne @JoinColumn (name = "foo_id", nullable = false) Private Fu Foo; ...} @ Entity @ Pririke Join column (name = "BIID") Public category B {...} @ Entity @ Prireakeke join column (name = "CIID") Public category C {...}   

and Foo unit -

  @Entity Public Square Fu {@ Private Private ID ID; @OneToOne (cascade = CascadeType.ALL, mapped = "foo") left private // a // getters / setters}   

I now use the unit Foo The reference of the field B has been saved. Later, I want to update the example of FU as the C in the context of class as 'a'. What did I do -

  loadedFooInstance set A (new C ()); EntityManager.merge (loadedFooInstance);   

But what I notice - it does not remove the original B object which was assigned to the Foo object before specifying c. For this reason, all the references I have allotted to me must be removed for that FU example manually before specifying a new one. But I believe that hibernation should be used to deal with such scenarios. Something is missing in the way and in my mapping Is anything wrong in my mapping or can this type of mapping be achieved better, so I do not have to deal with such manual work. Land.

If your OneToOne relationship is not managed by one-side by Foo-side, then you have A-side But the relationship needs to change (because pay attention to hibernation towards the side where the relationship is managed) an old = loaded FooInstance.getA (); OldA.setFoo (zero); Cc = new c (); C.setFoo (loadedFooInstance); / * And it is also good to update Foo / loadedFooInstance.setA (c);

On the other side, the side which manages relationships is to change:

  public abstract class A ... ... @OneToOne (mapped = " A ") private Phu Fu; ...} public class Foo {... @OneToOne @JoinColumn (name = "a_id", nullable = false) Private A ... ...   

but it changes your database Will also give layouts!

Comments