EclipseLink / JPA: some @DiscriminatorColumn annotations for Entity

I am looking for a way in EclipseLink to have two @DiscriminatorColumns on the same entity

Table of my PostreSQL DB:

Dictionary
{
  id,
  object_type,
  attribute_type,
  translation
}

And classes:

@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;

I am trying to ensure that when I call the word DictionaryAttributeName, it will be resolved as SQL:

select * from DICTIONARY where info_type = 1 and object_type = 0

But in fact, it takes the DiscriminatorColumn class from the DictionaryRow class and DiscriminatorValue from the AttributeName dictionary, which leads to completely incorrect SQL:

select * from DICTIONARY where object_type = 1

Is there a solution for this problem?

thank

+3
source share
1 answer

According to the JPA 2.0 specification, this is not possible:

11.1.10 Discriminator

SINGLE_TABLE , , JOINED , . DiscriminatorColumn SINGLE_TABLE JOINED .

-, .

  • JPA 2.0
    • 11.1.10 " "
+2

Source: https://habr.com/ru/post/1769556/


All Articles