File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Bidirectional @OneToOne with JoinTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Bidirectional @OneToOne with JoinTable" Watch "Bidirectional @OneToOne with JoinTable" New topic

Bidirectional @OneToOne with JoinTable

Subhendu Mahanta

Joined: Jan 28, 2011
Posts: 5
I have 2 entities :Customer & Address.

With @OneToOne and @JoinTable looks like this:


When I try to persist a customer I get the following stack-trace:

I have tried this change in Address entity:

with no effect. Surely this could be done without using JoinTable.But I want to do it this way for academic interest.Is it possibe?
Ran Pleasant
Ranch Hand

Joined: Jan 16, 2003
Posts: 76
I assume that this design is part of a learning experience. However, if this is a production design then you should ask yourself, Does an address really need to point back to its owner?

Subhendu Mahanta

Joined: Jan 28, 2011
Posts: 5
Thanks Ron.
You are correct that this is part of a learning experience.There is no need for address to point back to customer.Let's say there are 2 entities A & B which have a bi-directional association. In that case I think shared primary key will be the preferred technique.
Subhendu Mahanta

Joined: Jan 28, 2011
Posts: 5
I wanted to mean "Thanks Ran".Sorry for the typo.
I agree. Here's the link:
subject: Bidirectional @OneToOne with JoinTable
jQuery in Action, 3rd edition