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: how to map a table per subclass
PostPosted: Fri Aug 26, 2005 3:55 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:38 pm
Posts: 56
Location: Austin, TX
Hibernate version:
3

Name and version of the database you are using:
postgres 8

I was hoping someone might be able to give me some insight on how to map the following situation:

Code:
create table human (
    id serial primary key,
    hair_color text
);

create table person (
    id serial primary key,
    human_id integer references human,
    name text
);


-----------------
HUMAN
-----------------
id | hair_color
----+------------
  1 | brown
  2 | black
  3 | blonde
  4 | red


----------------------
PERSON
----------------------
id | human_id | name
----+----------+------
  1 |   1      | mike
  2 |   1      | dan
  3 |   1      | fred


public class human {
    Integer id;
    String hair_color;
}

public class person extends human {
    Integer id;
    String name;
}





I looked into trying to map this using a table-per-subclass, but it seems this type of mapping is for a one-to-one mapping. I want a one-to-many mapping and it seems that it is possible from Table 10.1. Features of inheritance mappings from

http://www.hibernate.org/hib_docs/v3/reference/en/html/inheritance.html

but I could find any documentation on it. Could someone suggest how I might map these or point me to where I might find this in the docs?

The only way I could see how I might do this is via:

Code:
public class person {
    Integer id;
    String name;
    human h;
}


thanks in advance,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 27, 2005 2:21 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
Is this an abstract question or do you really have a seperate table for two synonyms?

If you are trying to somehow normalize hair color, make a seperate table called hair_color and put a forign key to it in the other person/human table.


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.