-->
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: Mapping Embeddable+Inheritance POJO
PostPosted: Tue Oct 25, 2011 12:16 pm 
Newbie

Joined: Tue Oct 25, 2011 11:18 am
Posts: 1
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?


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.