I have a very simple setup to try bidirectional mapping with annotations:
< Code> @ entity public class type a abber modell and lieutenant; Type A & gt; {@Id @GeneratedValue Private INAD; @OneToMany (mapped = "A") private collection & lt; TypeB & gt; Bs; // Gates & amp; Setters ...}and
@EntiType public class TypeB abber modell extension & lt; TypeB & gt; {Private Stable Last Long Serial Year UID = 3526384868922938604 L; @ ID @ Generated Private Private ID; @ManyToOne () @ Zone column (name = "A_ID") Private type AA; }
When I set property TypeA.bs it does not affect mapping, although this should look like the following example:
TypeB b = new TypeB (); This.typeBDao.save (b); TypeA a = new type A (); A.setBs (ListUtils.createList (b)); Println (a.getBs ()); // Output: [TypeB @ 25fe4d40] this.typeADao.save (a); Println (a.getBs ()); // Output: [TypeB @ 25fe4d40] this.Typeadao.refresh (a); Println (a.getBs ()); // Output: [] This Type BDO.refresh (b); Println (b.getA ()); // Output: blank
If the mapping is bidirectional, the collection must be populated and the property should be updated B, but it is not. Any ideas?
Edit Thank you for helping people, I got it now!
For a consistent domain model, you should always set both sides of the relationship, such as:
TypeB b = new TypeB (); TypeA a = new type A (); A.setBs (ListUtils.createList (b)); B.setA (a); This.typeBDao.save (b); This.typeADao.save (a);
When your institutions are in an incompatible situation, then the JPA will always collect the values according to the object's condition of the owner side of the JPA relationship. In this case type B is the owner of the type of type. Thus if there is no reference to an object type A of TypeB, then the JPA assumes that no relation is defined.
Comments
Post a Comment