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: Hibernate / JPA Inheritance:
PostPosted: Sat Jul 11, 2009 6:25 am 
Newbie

Joined: Sat Jul 11, 2009 5:59 am
Posts: 1
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.


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.