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
|