I have a db schema:
Table id long PK
attr1 String
attr2 String
....
attrN String
TYPE String
VAL1 String
VAL2 String
VAL3 String
I need:
if TYPE == 'A' then VAL1={same value}, VAL2=null, VAL3=null
if TYPE == 'B' then VAL1=null, VAL2={same value}, VAL3=null
if TYPE == 'C' then VAL1=null, VAL2=null, VAL3={same value}
My pojo structure:
Code:
@Entity
public class Table {
@Id
public long id;
public String attr1;
public String attr2;
....
public String attrN;
@Embedded
public MyVal myVal;
}
@Embeddable
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING)
public abstract class MyVal {}
@DiscriminatorValue("A")
public class MyValA extends MyVal {
public String val1;
}
@DiscriminatorValue("B")
public class MyValB extends MyVal {
public String val2;
}
@DiscriminatorValue("C")
public class MyValC extends MyVal {
public String val3;
}
But this structure isn't work.
SELECT t FROM table t
When query are executed i have next result:
{id=1,myVal=null}
{id=2,myVal=null}
I am tired. Where am I wrong? Maybe are there other ways?