-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can 3 class map on 1 table?
PostPosted: Fri Feb 17, 2006 12:26 am 
Newbie

Joined: Fri Feb 17, 2006 12:18 am
Posts: 11
Hi, I have 3 class with one-one-one relationship to map. so I want to map these 3 class on 1 same table:

Code:
class A {
Long ID;
String a;
}

class B {
Long ID;
String b;
}

class C {
Long ID;
String c;
}


can these 3 class map on 1 table:

Code:
ID BIGINT
VARCHAR(10) A
VARCHAR(10) B
VARCHAR(10) C


and use 1 same primary key?

thx!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 4:02 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Perhaps you can use component mapping ?
See chapter 5.1.13.

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 5:08 am 
Newbie

Joined: Fri Feb 17, 2006 12:18 am
Posts: 11
steckemetz wrote:
Perhaps you can use component mapping ?
See chapter 5.1.13.


I know component cannot have OID, but there is 3 individual businesses based on 1 table.

for example, a "Customer" table with many fields.

the login system only needs fields: ID, username, password.

the shoping system only needs fields: ID, truename, address, zipcode.

the email system only needs fields: ID, email.

maybe there will be new business needs other fields. e.g.: a blog system needs ID, blogTitle, articleCount, imageCount ...

these 3 class are not related but share the same primary key. also i don't want to use 1 class to hold all fields that may reduce performance.

can I use 3 classes but map them onto 1 table?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 10:24 am 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
As far as I know it is possible to map as many classes on a single table as you want. However I wouldn't recommend it as it would defeat most Hibernate features : if you save one 'A', how is Hibernate supposed to know that a 'B' and a 'C' have been created to ?
In your case, I would use a single class, implementing 3 interfaces IA, IB, IC, and maybe a factory for instanciations.
If your concern is performance (don't want to load Bs properties if you just need an A), you can still use property lazy fetching.
http://www.hibernate.org/hib_docs/v3/reference/en/html/performance.html#performance-fetching-lazyproperties

Hope this helps


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