Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This is a similar problem to "Hibernate @OneToMany without a separate join table", in that I need a @OneToMany relationship without a join table. However, I would also like to not define the inverse relationship. Removing the inverse seems to result in a join table being automatically generated... is there a workaround for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
532 views
Welcome To Ask or Share your Answers For Others

1 Answer

In JPA 2.0+ you can use @JoinColumn as a way to avoid to generate joined table.

Try it.

@OneToMany
@JoinColumn(name="COLUMN_NAME")

UPDATE

The info provided above has been extracted from EJB 3.0 o'reilly book (Look for The @JoinColumn annotation references the CUSTOMER_ID column in the PHONE table). However, plain JPA 1.0 specification does not support this feature. What it says is

Unidirectional one-to-many relationships may be implemented using one-to-many foreign key mappings, however, such support is not required in this release. Applications that want to use a foreign key mapping strategy for one-to-many relationships should make these relationships bidirectional to ensure portability

So in 1.0 it is a vendor-specific implementation (And it makes sense, The author works at JBoss - The red hat divison behind the hibernate)

But it is supported by JPA 2.0 implementation

If the join is for a unidirectional OneToMany mapping using a foreign key mapping strategy, the foreign key is in the table of the target entity.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...