This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Foriegn key mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Foriegn key mapping" Watch "Foriegn key mapping" New topic

Foriegn key mapping

sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81

I have two tables as below.

Table Employee(
Employee_Id: Integer(11)
Employee_Name: Varchar(22)

Table Employee_Address(
Emp_Id: Integer(11) FK -> Employee
City: Varchar2(30)

All I want When ever a record is entered in Employee_Address, That record must have a mapping in Employee(Employee_Id) table.

I went through many articles on this.. many of them suggested that... in Employee .java should contain an object and setters/getters for Employee_Address. I dint understand this. Because if I do like this...I need to fill Employee_Address object to enter any record in Employee table.

I want Employee record to be entered with out any Employee_Address details. But to enter a record into Employee_Address must have a record in Employee.

Please clear me on this.


sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81
Please help me any one.

Larry Frissell
Ranch Hand

Joined: May 16, 2008
Posts: 82
I believe you want to use a one-to-one mapping relationship. See this link for an example with employee name and address.
sammeta Phanikumar
Ranch Hand

Joined: Oct 25, 2007
Posts: 81
Thanks Larry for your reply,

But in this example if I want to enter a record only in Employee table then i have to setAddress with an Address object. this i do not want.

I just want work with Employee independently. But a record in Address must a have reference in Employee table.

Please help me in this...

I agree. Here's the link:
subject: Foriegn key mapping
jQuery in Action, 3rd edition