wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes OneToMany Unidirectional relationship without Join table (JSR 220) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "OneToMany Unidirectional relationship without Join table (JSR 220)" Watch "OneToMany Unidirectional relationship without Join table (JSR 220)" New topic
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: 4968
    
    1

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.
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: 16022
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OneToMany Unidirectional relationship without Join table (JSR 220)