These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping multiple objects from a single column
PostPosted: Sat Jan 03, 2009 1:35 pm 
Newbie

Joined: Thu Dec 06, 2007 1:03 pm
Posts: 4
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


Top
 Profile  
 
 Post subject: Solved
PostPosted: Sun Jan 04, 2009 1:36 am 
Newbie

Joined: Thu Dec 06, 2007 1:03 pm
Posts: 4
@JoinColumn(name="id) @OneToOne
private Main main


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.