Reputation: 151
I'm looking for a way in EclipseLink to have two @DiscriminatorColumns on the same entity
My PostreSQL DB table is:
Dictionary
{
id,
object_type,
attribute_type,
translation
}
And classes are:
@Entity
@Table(name = "dictionary")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="object_type",
discriminatorType=DiscriminatorType.INTEGER)
public class DictionaryRow implements Serializable;
@Entity
@DiscriminatorValue("0")
@DiscriminatorColumn(name="info_type",
discriminatorType=DiscriminatorType.INTEGER)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class DictionaryAttribute extends DictionaryRow;
@Entity
@DiscriminatorValue("1")
public class DictionaryAttributeName extends DictionaryAttribute;
What I'm trying to achieve is that when I call for DictionaryAttributeName it will be resolved to SQL like:
select * from DICTIONARY where info_type = 1 and object_type = 0
But actually, it takes the DiscriminatorColumn from the DictionaryRow class, and DiscriminatorValue from the DictionaryAttributeName, resulting in the totally wrong SQL:
select * from DICTIONARY where object_type = 1
Is there a solution for this issue?
Thanks
Upvotes: 3
Views: 2871
Reputation: 570385
According to the JPA 2.0 specification, this is not possible:
11.1.10 DiscriminatorColumn Annotation
For the
SINGLE_TABLE
mapping strategy, and typically also for theJOINED
strategy, the persistence provider will use a type discriminator column. TheDiscriminatorColumn
annotation is used to define the discriminator column for theSINGLE_TABLE
andJOINED
inheritance mapping strategies.The strategy and the discriminator column are only specified in the root of an entity class hierarchy or subhierarchy in which a different inheritance strategy is applied.
Upvotes: 2