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 Toplink One Class From Two Seperate Table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Toplink One Class From Two Seperate Table" Watch "Toplink One Class From Two Seperate Table" New topic

Toplink One Class From Two Seperate Table

Jeremy Ragsdale

Joined: Apr 23, 2009
Posts: 1
Hi all,

I have a simple table structure of Employees & Employee Extra Data - I Don't know why they split this out, anyway...

Here's My Environment
SqlServer 2005
SQL Driver jtds1.2.2.jar
Windows XP

I have used Create Java Objects from Tables to Create My POJO's for Each Table but what I really want is one class that represents some data from both tables.
I tried Using a view but The Datasource is SQL Server and for some reason Toplink is not liking the view?

What I want is a Class that Has all the employee data plus a few of the fields from the Employee Extra Data Table.

How I am getting around this is to add the fileds manually to the Employee class then

Employee = EmployeeByID(int id)
EmployeeExtraData = FindEmployeeExtraDataByID(int id)

This works of course and for one employee is not that big of a deal but what happens when I do a wildcard serach that returns 1000+ employees.

I will have to loop through each record to update the Mobile field???

There has to be a better way to do this?

Can anyone please help.

Thanks in advance

James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
You should use a multiple table descriptor for the Employee class. i.e. Just map the class to both tables, then TopLink will join the data.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
I agree. Here's the link:
subject: Toplink One Class From Two Seperate Table
It's not a secret anymore!