Hi guys,
may I ask a question about inserting of the entity which inherits from the master entity? I'm completely new to hibernate, so I apologize, if my question will be silly..:-)...However, I have this scenario...
Code:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
class Person implements Serializable {
private String id;
private String name;
private String surname;
public Person (Person person) {
copy constructor....save all properties...
}
// settrs, gettrs
}
From this entity inherits another entity
Code:
@Entity
@PrimaryKeyJoinColumn(name = "id")
class OtherUser extends Person {
private Date validity;
public OtherUser ( Person person ) {
super(person);
this.validity = ....
}
// settrs, gettrs
}
Now I want to create new entity instance of OtherUser from an existing instance of Person....something like this..
Code:
Person person = .....process which returns Person instance
OtherUser user = new OtherUser (person);
hibernatteSession.persist (user);
But when I tried my code, hibernate told me that he's not able to bind instance of OtherUser with Person, 'cause he didn't find a key of the Person instance. Please what I'm doing wrong? Do you have an example, which would illustrate how can I achieve this goal?
many thanks in advance
new hibernate user
Tomas
[/code]