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
detail-table.
thanks for your explanation,
Uden
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:
http://www.nabble.com/Question-about-%40OneToMany-tp16840368p17124365.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.