I'm trying to create a mapping between 2 objects which share a common "id". In other words, an "Extension" with an id of 7 should have a "getMain" method with returns a "Main" with an id of 7.
The tables are defined as:
Code:
create table Main (
id int primary key auto_increment,
data varchar(50)
);
create table Extension (
id int primary key not null,
otherfields varchar(50)
);
Note that "id" in Main is an autoincremented value, and that value is used to create a complementary Extension record. There is a foreign key (not shown) between the tables based on their "id" fields, creating a one-to-one relationship where each Extension record belongs to one and only one Main record.
Main is realized as a class:
Code:
@Entity
public class Main {
@Id @GeneratedValue
private long id;
@Column
private String data;
}
I do not know how to correctly define the annontation in Extension (see comment):
Code:
@Entity
public class Extension {
@Id
private long id;
//Is this @JoinColumn or @OneToOne - something else?
private Main main;
@Column
private String otherfields;
}
So, how do I use "id" to tie these two objects together without requiring a "main_id" or "extension_id" in each table? Any suggestions are appreciated.
Todd