Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Secondary table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Secondary table" Watch "Secondary table" New topic

Secondary table

rani vini

Joined: May 13, 2009
Posts: 24
How can map these two tables using secondary table
Table EMP
Table DEPT

Where EMPID refers to the ID column of EMP

My mapping calss is like below
@PrimaryKeyJoinColumn( name = "EMPID", referencedColumnName = "ID")
public class Employee {
@GeneratedValue(strategy=GenerationType.AUTO, generator="EMP")
@SequenceGenerator(name="EMP", sequenceName="SEQ_EMP")
long Id;

String empName;

String deptName;

When I try to persist like below

Employee empObj = new Employee();

It is displayign the Sql statements like
Hibernate: insert into emp (EMPNAME, Id) values (?, ?)
Hibernate: insert into dept (deptName, Id) values (?, ?)
In DEPT table there is no "ID" column. So Iam getting error.
The insert Statement for DEPT should contain "DEPTNAME and EMPID" instead of "DEPTNAME AND ID"

Can anyone help?
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi rani vini..

May i know your goal using Secondary Table ?..
Thanks in advance...

Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Could it be the referencedColumnName = "ID" element?

-Cameron McKenzie
It is sorta covered in the JavaRanch Style Guide.
subject: Secondary table
Similar Threads
hybernate doubt
Problem with all-delete-orphan
Strange Behavior of Hibernate - NOT RESPONDING
INDEX PROPERTY <html:form> with nested beans
Performance concern with Select Query