-->
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: Mixing Inheritance with annotations
PostPosted: Sat Nov 10, 2007 3:50 pm 
Newbie

Joined: Tue May 29, 2007 6:23 pm
Posts: 11
Hi to all,
Is is possible to mix InheritanceType.JOINED with InheritanceTable.SINGLE_TABLE with a three level inheritance hiearchy like the following:
Code:
          A (anottated with InheritanceType.JOINED)
         /  \
        B   C (both have attributes, B annotated with InheritanceType.SINGLE_TABLE)
       /  \
      D   E (no attributes, annotated with DiscriminatorValue)

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class A  {
....
}

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class B extends A {
...
}

@Entity
public class C extends A {
...
}

@Entity
@DiscriminatorValue("0")
public class D extends B {
...
}

@Entity
@DiscriminatorValue("1")
public class E extends B {
...
}

I think it is not possible, since when I tried to persist a D object I get a "Table or view does not exists" error, while on the other hand could persist a C object without any problems.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 13, 2007 6:40 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
I also want a 3 level heirarchy:

Code:
          A (annotated with @MappedSuperclass)
         /  \
        B   C (These use table per class. General business entities)
       /  \
      D   E (no attributes, annotated with DiscriminatorValue)



Class "A" is our "BaseEntity" class. It defines the id, version, and an audit embedded object wich we want all our business entities to have. The entities are all on seperate tables of course.

All our business entities are instances of BaseEntity. This is very convenient.

But now we want another subclass heirarchy below that with class "B" which is in fact called "Preference" being the root of a new subclass heirarchy which uses SINGLE_TABLE strategy.

Our user preferences are all going to be keyed similarly, only the value held will change between the different types, so what we need is one Preference table, a "preference_type" discriminator column, and there will be columns for each subclass's value type.

What is is creating is seperate tables for each subclass of Preference.

The Preference table is being created with the discriminator column! But its subclasses get seperate tables in spite of Preference having:

Code:
@Entity
@Inheritance(strategy=SINGLE_TABLE)
@DiscriminatorColumn(name="PreferenceType", discriminatorType=INTEGER)
public abstract class Preference extends BaseEntity implements Serializable {


It appears that Hibernate inheritance can only be one level deep?!!!

Can that possibly be true?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 13, 2007 8:04 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
Ahah!

The trick is to not add the Preference class to the Ejb3Config object. (We use programmatic configuration using annotations)

It does not need to be explicitly told about that, the subclasses reference it, so it is examined by default.

It seems to create a correct schema now.


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.