I have a question about Hibernate. I’m using 3.1.3 version and I have two classes, one inherits the other. This is my scenario:
//User class, which is stored in the database and hibernate mapped
public class User
//Logged user class, this is a bean which inherits from user and
//stores only user information and some session data
public class LoggedUser extends User
Somewhere in my code I get the LoggedUser bean from my session, and I assign it to a User variable.
User user = Session.getBean("LoggedUser");
This can be done without cast, but when I try to store the “user” object into my database I’ve got an “unknown entity” error, because hibernate doesn’t recognize LoggedUser is extending User class.
There are lots of tutorials about implementing inheritance in Hibernate, but I’m not interested in saving LoggedUser extra properties, I only want to store that information which is in User table. Any idea?
I am not sure about the clean solution, but here are some tips which might lead you to some.
Hope this takes you to the bright side.