-->
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.  [ 1 post ] 
Author Message
 Post subject: Inheritance/Discriminator doesn't work on MappedSuperclass
PostPosted: Thu May 03, 2007 3:06 pm 
Newbie

Joined: Fri Apr 15, 2005 7:52 pm
Posts: 13
Hi,

Is it possible with Hibernate3 to annotate table, inheritance and discriminator column in a MappedSuperclass (not an Entity)?

Example:

@MappedSuperclass
@Table(name="A_TABLE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.INTEGER)
public abstract class A {
...
public abstract getType() {
...
}
...
}

@Entity
@DiscriminatorValue("1111")
public class B extends A {
}

@Entity
@DiscriminatorValue("2222")
public class C extends A {
}

This doesn't seem to work - as soon as you use the @MappedSuperclass annotation on the abstract base class, the annotations @Inheritance, @Table and @DiscriminatorColumn will be ignored.

The only workaround seems to be to make the base class an entity and assign it a bogus @DiscriminatorValue, e.g.

@Entity
@Table(name="A_TABLE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
public abstract class A {
...
public abstract getType() {
...
}
...
}

The first example though seems more intuitive and the EJB3 spec is unclear about this (it only mentions that MappedSuperclass "cannot have a separate table"). Strictly spoken this looks like a bug/oversight. Anyone knows a workaround that would yield a similar result WITHOUT making the abstract base class an entity? TIA


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.