jpa newbie: Exactly what is 'mappedBy'
Although I have read the tutorials and examples, I fail to comprehend what is accomplished by the 'mappedBy' annotation.
All examples I have seen use the lowercase of the entity class name as its value. It seems like its always a default.
Related to this (and maybe if I 'get' this I'll understand the aforementioned), which entity is the 'owning' entity?
Thanks
nat
[405 byte] By [
nnatgrossa] at [2007-11-26 21:37:11]

# 1
Hi nat,
mappedBy is used for bidirectional relationships within the "inverse" (not the owning) entity. It
tells the persistence provider the name of the corresponding property or field in the owning entity.
The reason that pattern is prevalent is it's common for an Entity called Foo to have a relationship
accessor called getFoo().When you apply the Java Beans property naming rules, that becomes "foo", which is what would be assigned to the mappedBy attribute.
In the case of a uni-directional relationship, the owning entity is the entity that defines the
relationship.In the case of a bi-directional relationship, the owning entity is the one that
*doesn't* define mappedBy :-)
You can find more info on relationship mapping in section 2.1.7 of the persistence spec.
--ken
# 2
Let me see if I get the terminology.
Entities: Customer , Order.
Customer has a oneToMany annotation in front of the method that returns a Collection of Orders. Do we then say that Order is the owning entity?
Order has a manyToOne annotation in front of the getCustomer method. Can Customer be the owning entity? Is there a rule or pattern for this? Why would I want one over the other?
Thanks
nat