-->
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.  [ 5 posts ] 
Author Message
 Post subject: multiple DiscriminatorColumn's in Single Table Ineritance
PostPosted: Fri Mar 10, 2006 9:23 pm 
Newbie

Joined: Fri Mar 10, 2006 8:52 pm
Posts: 5
Is there any facility for having multiple DiscriminatorColumns when implementing Single Table per Class Hierarchy Inheritance?? Consider the following table:

BILLABLE_OBJECT
{
ID VARCHAR,
BILLING_SCHEDULE_TYPE VARCHAR, // YEARLY or MONTHLY
IS_FINANCABLE VARCHAR, // YES or NO
PRICE REAL
}

What if the class then depended on both the BILLING_SCHEDULE_TYPE and the IS_FINANCABLE fields to make a class hierarchy like the following:

abstract class Billable
{
...
}

// if BILLING_SCHEDULE == MONHTLY
abstract class MonthlyBillable extends Billable
{
....
}

// if BILLING_SCHEDULE == MONTHLY and IS_FINANCABLE == YES
class FinancableMonthlyBillable extends MonthlyBillable
{
..
}

// if BILLING_SCHEDULE == MONTHLY and IS_FINANCABLE == NO
class NonFinancableMonthlyBillable extends MonthlyBillable
{
...
}

// if BILLING_SCHEDULE == YEARLY
class YearlyBillable extends Billable
{
...
}

// if BILLING_SCHEDULE == YEARLY and IS_FINANCABLE == YES
class FinancableYearlyBillable extends YearlyBillable
{
...
}


// if BILLING_SCHEDULE == YEARLY and IS_FINANCABLE == NO
class NonFinancableYearlyBillable extends YearlyBillable
{
...
}

This hierarchy can be represented in one table where the class of a row is determined by more than one field in the table. In my current database I currently have a situation similar to the above example. If only one DiscriminatorColumn can be specified for a class then I cannot support my class hierarchy in EJB3.0 annotation semantics, as the way it currenly works is by using several fields to determine the class of a row. Is there any way to support this in ejb 3.0, other than adding a new column to my table that is a concatenation of the other columns that are used for determining object class, and then using it as the DiscriminatorColumn??


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 2:28 pm 
Newbie

Joined: Fri Mar 10, 2006 8:52 pm
Posts: 5
I've noticed that there is a hibernate specific way to do this by using @DiscriminatorForumla, but this is hibernate extension and not a part of the EJB3.0 spec. Is there any way to achieve the above that conforms to the ejb3.0 spec??


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 5:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
not in an EJB3 compliant way

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 9:05 pm 
Newbie

Joined: Fri Mar 10, 2006 8:52 pm
Posts: 5
if necessary, I may try using the hibernate extension for doing this. However, I couldn't really tell how to use the @DiscriminatorForumla from the documentation I found at http://www.hibernate.org/hib_docs/annot ... ml#d0e1999

It only shows the following:

@Entity
@DiscriminatorForumla("case when forest_type is null then 0 else forest_type end")
public class Forest { ... }

Is there some more documentation available for this annotation and/or possibly even an example somewhere that shows how to use it?? Any information regarding this would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 8:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
there should be some examples of formula in a discriminator in the hibernate core reference documentation

_________________
Emmanuel


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