Skip to main content

Just curious...why can't @OneToMany use a default for mappedBy?

3 replies [Last post]
cayhorstmann
Offline
Joined: 2003-06-13

The EJB3 creators did a very nice job with annotation defaults in most cases--I am sure they thought about them very carefully. I am curious why they required mappedBy in @OneToMany.

Every time I use @OneToMany it is exactly like in the example of the spec (p. 179)

In Customer class:
@OneToMany(mappedBy=”customer”) // <-- why necessary?
public Set getOrders() { return orders; }
In Order class:
@ManyToOne
public Customer getCustomer() { return customer; }

Why can't @OneToMany's mappedBy default to "the property of the target class with the same name as the source class"?

Thanks,

Cay

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04

Cay,

One of the reasons would be the case when there is more than
one set of relationships between 2 entities. But the best
way to get an answer from people who are writing the spec
is to ask your question on the feedback alias.

Regards,
-marina

cayhorstmann
Offline
Joined: 2003-06-13

Thanks! What is that alias?

Cheers,

Cay

ss141213
Offline
Joined: 2005-03-30

> Thanks! What is that alias?

ejb3-pfd-feedback@sun.com