File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OneToMany Unidirectional relationship without Join table (JSR 220)

 
Rahul Juneja
Ranch Hand
Posts: 425
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Edvins Reisons
Ranch Hand
Posts: 364
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 364
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 425
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cameron,

Thanks for the help, but i guess i am looking for unidirectional without the join table.

Thanks,
Rahul
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Juneja
Ranch Hand
Posts: 425
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic