| Author |
OneToMany Unidirectional relationship without Join table (JSR 220)
|
Rahul Juneja
Ranch Hand
Joined: Aug 03, 2002
Posts: 425
|
|
Folks, I was just going through JPA Specs(JSR 220) and this doesn't seems to support Unidirectional relationships with two tables until and unless we have a join table in between. Do you think i have any other alternative if i don't want to create a join table or don't want to have a bidirectional relationship. Thanks, Rahul
|
Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
|
 |
Edvins Reisons
Ranch Hand
Joined: Dec 11, 2006
Posts: 364
|
|
|
Yes, according to the specification, a join table is the default implementation, and other implementations are optional.
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
Here is a sample tutorial that uses Hibernate and JPA annotations to map a bi-directional one-to-many and many-to-many relationship, and there is no join table needed:  Mapping One-to-Many and Many-to-One Bi-directional Relationships  Now, for a many-to-many relationship, you need that join table, but I don't see the need on basic one to one and one to many relationships.
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
Edvins Reisons
Ranch Hand
Joined: Dec 11, 2006
Posts: 364
|
|
Cameron, I agree with your "I don't see the need..." statement, and yet this is what the specification says (from p. 9.1.24):
The default schema-level mapping for unidirectional one-to-many relationships uses a join table, as described in Section 2.1.8.5. 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.
|
 |
Rahul Juneja
Ranch Hand
Joined: Aug 03, 2002
Posts: 425
|
|
Cameron, Thanks for the help, but i guess i am looking for unidirectional without the join table. Thanks, Rahul
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14568
|
|
What is your JPA implementation? The Apache OpenJPA system does support joins without a join table and I've been using it extensively for some time. In fact, I'd expect most serious JSR-220 implementations to support table-less joins for the simple reason that too many legacy databases were designed with direct foreign key linkages.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Rahul Juneja
Ranch Hand
Joined: Aug 03, 2002
Posts: 425
|
|
Tim, You are right we are stuck in a situation with some old legacy database without a join table. That does make sense to have a unidirectional without the join table. Thanks, Rahul
|
 |
 |
|
|
subject: OneToMany Unidirectional relationship without Join table (JSR 220)
|
|
|