• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Bidirectional One-To-One using @PrimaryKeyJoinColumn

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[p-277 of EJB3 In Action Book] talks about only unidirectional one-to-one. How about bidirectional one-to-one using @PrimaryKeyJoinColumn? Do i have to specify
mapped-by attribute as i did it for bidirectional one-to-one using @JoinColumn.
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any help on this ?
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a bi-directional OneToOne, then you should always use mappedBy in the direction opposite to the foreign key constraint.
There are basically two pieces of information in the OneToOne, which foreign key field should be written to from the relationship, and whether the source or target should be inserted to the database first.

Using mappedBy, means don't write any foreign keys from the reference, and insert this object first.
Using a @PrimaryKeyJoinColumn means the object has foreign keys, but because it also maps them using basic Id attributes, don't write to any of the foreign keys from the reference, and insert the referenced object first.
Using a @JoinColumn means the object has a foreign key, write to it from the reference (unless it is insertable/updateable false), and insert the referenced object first.


http://en.wikibooks.org/wiki/Java_Persistence/OneToOne#Target_Foreign_Keys.2C_Primary_Key_Join_Columns.2C_Cascade_Primary_Keys
 
    Bookmark Topic Watch Topic
  • New Topic