openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Uden <>
Subject Re: Question about @OneToMany
Date Thu, 08 May 2008 10:17:03 GMT

The solution quoted below but has a consequence for the Java class model: the
OneToMany relationship becomes bi-directional instead of uni-directional. 

What is the reason for creating the join-table? 

I thought (based on my database experience) that a join-table is only
required for ManyToMany relationships. 
If you look at the data in the join-table of a uni-directional relation (no
mappedBy attribute), the relation between the join-table and master table is
always OneToOne, so this relation could be handled by a FK-field in the

thanks for your explanation,

Andy Schlaikjer-2 wrote:
> Marco Schwarz wrote:
>> How can I make only 2 tables?
> Here's my guess:
> First, use the "mappedBy" property of the @OneToMany annotation, like
> this:
> @Entity
> class ModelObject {
>    ...
>    @ManyToOne
>    ModelObject parent;
>    @OneToMany(mappedBy="parent")
>    List<ModelObject> children;
>    ...
> }
> This way, an extra join table won't be necessary to encode the parent 
> child relationship. Only the "parent_id" column in the "ModelObject" 
> table will be used to encode the relationship.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message