-->
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 problem
PostPosted: Wed Oct 21, 2009 10:13 am 
Newbie

Joined: Wed Oct 21, 2009 10:03 am
Posts: 1
Hi all, I have the following problem:


@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "group", discriminatorType = DiscriminatorType.STRING)
class Person {
String name;
...
Group group; //enum

}
@Entity
@DiscriminatorValue(value="FRIEND")
class Friend extends Person {
Location location; //enum
}


Now, if I'd like to make further inheritance based on the enum location, in order to get them all to the one and same table, what should I do?

I've tried following, but none of them works:

1. Without any additional annotation
class SchoolFriend extends Friend {
}


I got an exception that GROUP SchoolFriend doesn't exist

2. Use the same discriminatorvalue of the parent class
@Entity
@DiscriminatorValue(value="FRIEND")
class SchoolFriend extends Friend {
}

If I try to get a SchoolFriend instance:
entityManager.find(SchoolFriend.class, 1l)
I got a null although an object of SchoolFriend was just persisted

All I can get is a Friend object :
entityManager.find(Friend.class, 1l)
but I can't cast this to SchoolFriend

3. I used another discriminator column
@Entity
@DiscriminatorValue(value="FRIEND")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "location", discriminatorType = DiscriminatorType.STRING)
class Friend extends Person {
Location location; //enum
}

@Entity
@DiscriminatorValue(value="SCHOOL_FRIEND")
class SchoolFriend extends Friend {
}

--this one also doesnt work and I got the enum exception again that GROUP SCHOOL_FRIEND doesn't exist


would be very thankful for any tips

Regards


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.