Hi everyone,
I've got a fairly straightforward problem I'm hoping you can help me with. I have a class hierarchy with a User class at the top, and various subclasses of the User, such as SocialNetworkUser and ScoredUser.
When persisted, all these objects look the very same in the database, i.e. the only difference between these classes is that the subclasses have a few additional transient properties. I want to be able to load any row within my "users" table as any one of these object types.
I initially tried something like this:
Code:
@Entity
@Table(name = "users")
public class User {
...
}
@Entity
@Table(name = "users")
public class SocialNetworkUser extends User {
...
}
@Entity
@Table(name = "users")
public class ScoredUser extends User {
..
}
I get exceptions with the code above because the expected default discriminator column, "DTYPE" doesn't exist in my "users" table. In fact I don't want to define a discriminator column because these objects are identical in terms of persistence (the only difference being the aforementioned transient properties). It seems none of the JPA inheritance strategies (single table, joined, table per class) let me specify simply that all these objects persist identically.
If I annotate User as a @MappedSuperclass then I lose the ability to load User objects from the database.
So what is there to do? Any thoughts?
Thanks.