-->
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: DiscriminatorColumn two layers deep using SINGLE_TABLE
PostPosted: Fri Oct 10, 2008 5:48 pm 
Beginner
Beginner

Joined: Fri Sep 12, 2008 10:55 am
Posts: 33
I'm trying to figure out how to use DiscriminatorColumn when I have 1-2 different types.

Table mammal:
columns: ... order ..... species ...

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "order", discriminatorType = DiscriminatorType.STRING)
public abstract class Mammal ...


Code:
@Entity
@DiscriminatorValue( "Carnivora" )
public class Carnivora extends Mammal


Doing this works just fine. I have no problems with any multitude of other classes. Where I run into a problem is if I want another child class that will also have the set discriminator value, but also could break down even further based on another DiscriminatorColumn.

For example..let's say I have another class:

Code:
@Entity
@DiscriminatorValue( "Canidae" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn( name = "sub_species", discriminatorType = DiscriminatorType.STRING )
public abstract class Species extends Mammal


continuing with other types from there:

Code:
@Entity
@DiscriminatorValue( "Canis lupus familiaris" )
public class Dog extends SpeciesType


Code:
@Entity
@DiscriminatorValue( "Canis lupus" )
public class Wolf extends SpeciesType



This fails as shown above with the cannot instantiate abstract class Species when I come across one that is of type Canidae. However, changing the Species to a concrete class does return the Species class back to the caller - but what I'm really after is drilling further down to the Dog or Wolf class.

I'm not sure how this should be done - other than setting the Species class apart from the Mammal class and have to make different types of calls for what it is I'm looking for.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 1:25 pm 
Beginner
Beginner

Joined: Fri Sep 12, 2008 10:55 am
Posts: 33
I mis-typed in one of the class descriptions: "extends SpeciesType " is just supposed to be "extends Species".

However - to clarify on a simpler note:


Table :
columns : ... core_discriminator ... sub_discriminator

core_discriminator.....sub_discriminator
.........A................................' '
.........B................................' '
.........C................................CA
.........C................................CB
.........C................................CC


Consider that the discriminator columns are class names to keep things simple, I cannot figure out how to achieve this via SINGLE_TABLE

Basically what I have end up with class wise is:

abstract BaseClass
A extends BaseClass
B extends BaseClass
(abstract?) C extends BaseClass
CA extends C
CB extends C
CC extends C



If the core is "C", then I want to have the class CA, not class C. If I leave class "C" as concrete no matter what I end up with class C. Abstracting class C obviously throws an error as it is trying to instantiate an abstract class.

The real question is: Do I have to just separate these as two separate forms of work. i.e. add an @Where(clause = "core_discriminator != 'C'") and then let "C" just be a standard @Table entity?

Any help on this subject would be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 12:52 pm 
Beginner
Beginner

Joined: Fri Sep 12, 2008 10:55 am
Posts: 33
Does anyone have any thoughts on multiple discriminator columns that make up separate classes?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 2:44 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
As far as I know there can only be a single discriminator column, and there is also a limitation in the number of data types supported. See http://www.hibernate.org/hib_docs/v3/re ... criminator


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.