just starting my small personal project, which is another SAT words learning app. I have a data structure containing Word that has one or more possible Meaning(s). What would be a proper way of annotating the classes? So far i have
But Hibernate doc says "To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is not optimized and will produce some additional UPDATE statements."
I don't really understand what "owning side of the relationship" implies, but suppose that my Word should be the owning side in the case. Could maybe someone clarify this point and suggest a better mapping that does not "produce additional UPDATE statements".
Also what effect do the the directives "insertable = false, updatable = false" have?
The owning side of the relationship is the one that manges the relationship. I would put a mappedBy="word" on the OneToMany. This specifies that in this bi-directional relationship the Meaning class is the owning side. In a scenario such as this the @ManyToOne should always be the owning side and the @OneToMany is the non-owning or inverse side. If you do this you can drop the insertable and updatable attributes. These would no longer be needed, they specify whether it is 'Meaning''s responsibility to update or insert to this join column the reason they were required in your original mapping is because your @OneToMany was not inverse. This is suboptimal and would result in extra queries.
Note that the mappedBy automatically makes the relationship the inverse or non-owning side.