hibernate - Strange JPA one-to-many behavior when trying to set the "many" on the "one" entity -


I mapped two entities using JPA (especially Hibernate). Those entities have one-to-many relationships (I have simplified the presentation):

@Entity Public Sector A {@ManyToOne Public B getB () {Return b; }} @Entity Public Class B {@OneToMany (mapped = "B") public set & lt; A & gt; GetAs () {Return as; }}

Now, I am trying to make a connection between two instances of these institutions by using one set of relationships / non-owner-side setter (i.e. the table referred to Being):

  em.getTransaction (). Start (); AA = new A (); BB = new B (); Set up & lt; A & gt; Like = new hashset & lt; A & gt; (); As.add (a); (As) b.setAs; Em.persist (a); Em.persist (b); Committed to em.getTransaction ().  

But then, the relation is not sustainable for the DB (the row created for the ATT A is not referred to the row created for the unit B). Why is it like this? I try to work it out.

In addition, if I remove "mapped" property with @OneToMany comment, then will work again - why is it so? And what are the possible implications of removing "mapped" assets?

JPA spaces in bidirectional associations have been defined that the implementation only shows the association-owned side when He wants to see if the current "state" of the union is needed to determine whether the continuation of the union and the owner of the union of each bidirectional and inversion of both sides can avoid ambiguity (ie what to continue if the association Both of Q are not identical?) As well as offer opportunities and simple implementation for adaptation in J.A.A. applicants. Note that this is not usually a problem, because bidirectional associations should be maintained by you properly, not by J.P.A. When you always maintain bidirectional associations in your application (updating both sides and keeping them consistent), then there is no problem.

OneTomany is an inverse side with the map, so JPA impotions do not appear on this side when determining the position of the union on the flush / transaction commitment, it only appears on A.getB and it is zero, therefore SPAP is empty for JPA.

Without mapping, one-manjays, which becomes a proprietary side, is supported only after JPA 2.0, but I think it is for centuries to be in hibernation. That is why, If you remove the done from OneToMany then why your example works, in which case one-tony becomes the owner and therefore to determine whether the implementation is "visible" on this side, this fact will not be There is a compulsion that your In-Memory Association is still incomplete. You should set both sides.

UPDATE: I do not know what to do in hibernation when you leave the map from any side, but I think the result could be less optimal SQL. See also: section about "inverse" = "incorrect" section. JPA is the "inverted" country hibernate word for "mapped", that is, in hibernate mapping, similar to JPA using mapped = "true" mapped = "other", both sides interrupt this point Form which is ignored when determining the association updates.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -