Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

@OneToMany new reference table is generated.  RSS feed

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have OrderMain table and OrderItems tables with @OneToMany relationship in them. I set table schema to be generated automatically.
It generates a third reference table named OrderMain_OrderItems containing id from the OrderMain and OrderItems.
I wanted to have the Foreign Key to be there in OrderItems table referring OrderMain table id (PK).
Is there any setting to avoid the third referencing table and have the FK on the target side of the relationship.


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36634
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra,
Can you show the code? What you describe makes sense for a many to many relationship. I'm surprised to see it for a one to many.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

Below is the code I used:







persistence.xml


Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36634
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra,
Usually when I create a @OneToMany relationship, it is bi-directional. This would mean Order_Items would point to Order_Main.

The TopLink documentation says "configure the details of the join table used by TopLink JPA for uni-directional one-to-many relationships". Maybe the join table is being created in your example because Order_Main isn't being told which table Order_Items is in?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Jeanne
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!