-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Mapping Single table with two classes
PostPosted: Fri Dec 24, 2004 2:19 am 
Newbie

Joined: Fri Dec 24, 2004 2:02 am
Posts: 4
I have a single table consisting of columns
like


Table Name : Person
id: primary not null
name: not null
city: null
phone: null


class PersonInfo{
private long id;
private String name;

}
class Person extends PersonInfo{
private String city;
private String phone;

}

How can I map these two classes in a single mapping file


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 6:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please read the reference documentation, this is very basic and well explained.


Top
 Profile  
 
 Post subject: Re: Hibernate Mapping Single table with two classes
PostPosted: Fri Dec 24, 2004 8:59 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
vishnuos wrote:
I have a single table consisting of columns
like


Table Name : Person
id: primary not null
name: not null
city: null
phone: null


class PersonInfo{
private long id;
private String name;

}
class Person extends PersonInfo{
private String city;
private String phone;

}

How can I map these two classes in a single mapping file


Well this depends on how you want to map these classes. The simplest approach would be to map Person to the Person table, using the inheritied properties from PersonInfo explicitly.
However, what it seems like you want to do is to use some sub-classing. In this case you would need a discriminator colum in the Person table so that Hibernate can distinguish between persistent instances of PersonInfo and Person.

see: [url]http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-subclass
[/url]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.