Hello everybody,
I have a question about inheritance mapping in Hibernate. I need something like the opposite of the
Code:
@MappedSuperclass
annotation, because I want to persist only the objects of the superclass. I am getting crazy. Please take a look at this 2 simple classes...
Code:
@Entity
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String login;
private String password;
... getter & setter code
}
@Entity
public class RegisterForm extends User {
@Transient
private String passwordConfirm;
... getter & setter for added field.
}
.
The inheritance I used for convenience. The
Code:
RegisterForm
I only use for password confirmation input field.
When the user submits the form I want to persist the RegisterForm object as a User object in Database. At first I tried something like the following, but it is obvious that it does not work...
Code:
User user = (User) registerForm;
userDAO.persist(user);
Is there some easy way to make sure that objects of the subclass are persisted und handled in the exact same way as the superclass?
I also read about the inheritance strategies in hibernate, but these three strategies does not really fit to my problem. I do not want to have an extra table for the subclass and I do not want to have an extra row in my table to distinguish the objects of the superclass from the subclass objects, because they look are the same.
I also thougt about to copy all fields from a RegisterForm object to a new User object and persist it then, but my User class is much bigger than in my example above and there must be another nicer way.
Thank you very much in advance!
Dumbi