The mappedByelement in the one-to-one mapping of the employeeattribute of ParkingSpaceis needed to refer to the parkingSpaceattribute in the Employeeclass. The value of mappedByis the name of the attribute in the owning entity that points back to the inverse entity. The two rules, then, for bidirectional one-to-one associations are the following: • The @JoinColumnannotation goes on the mapping of the entity that is mapped to the table containing the join column, or the owner of the relationship. This might be on either side of the association. • The mappedBy element should be specified in the @OneToOne annotation in the entity that does not define a join column, or the inverse side of the relationship. It would not be legal to have a bidirectional association that had mappedByon both sides, just as it would be incorrect to not have it on either side. The difference is that if it were absent on both sides of the relationship, the provider would treat each side as an independent unidirectional relationship. This would be fine except that it would assume that each side was the owner and that each had a join column. Bidirectional many-to-one relationships are explained later as part of the discussion of multivalued bidirectional associations.
đang được dịch, vui lòng đợi..
