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: Class Hierarchy and Wide Tables
PostPosted: Thu Jul 07, 2005 6:52 pm 
Newbie

Joined: Fri Jun 03, 2005 6:22 pm
Posts: 1
Hibernate version:
3.0

Mapping Strategy Question
I'm converting a legacy application to Hibernate and got a single table in the database which is pretty wide [30+ columns]. The Java classes which this table maps to has a class hierarchy like this:

SearchModel
|
V
DetailModel

The SearchModel has about 10 columns from the table. The DetailModel extends the SearchModel class and has fields for the rest of the columns.

I tried using the "Table per Class Hierarchy" strategy and a single mapping file which holds the hibernate mappings for both SearchModel and DetailModel. I get this exception when I try to use the mapping file:

org.hibernate.MappingException: No discriminator found for [...]DetailModel. Discriminator is needed when 'single-table-per-hiearchy' is used and a class has subclasses.

The table actually has no column I can map the descriminator to, any row in the table could be mapped to either the SearchModel or the DetailModel.

My questions are these:

Is "Table per Class Hierarchy" the right strategy to use in this case? If it is, then how do I get around the discriminator requirement hibernate is complaining about?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 1:21 am 
Beginner
Beginner

Joined: Wed Jul 06, 2005 8:18 pm
Posts: 23
Table per class hierarchy does require a discriminator column. You may have to go with table per concrete class. Check out this article for further info:

http://www.agiledata.org/essays/mappingObjects.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:39 pm 
Newbie

Joined: Mon Aug 29, 2005 5:01 pm
Posts: 5
Could this be accomplished using the following?

<class name="Cat"
polymorphic="explicit"
discriminator-value="not null"
>
<discriminator column="cat_id"> <!-- never null -->
...

<subclass name="DomesticCat"
discriminator-value="not null"
>
...
<property name="domesticCatHome" column="home_addr"/>

</subclass>


</class>


In this case all rows will match both the Cat class and DomesticCat class, yet the returned type must be declared by the hql (polymorphic='explicit').

Am I mistaken in the meaning of the discriminator attributes? I'm trying to achieve a similar objective of the original post. I need the ability to return only a subset of the columns (due to security) and all columns programmatically.

Thanks!
PT


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.