• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OneToMany Unidirectional relationship without Join table (JSR 220)

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, according to the specification, a join table is the default implementation, and other implementations are optional.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cameron,

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

Thanks,
Rahul
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
It's a tiny ad only because the water is so cold.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic