Org.hibernate.WrongClassException
I am working on a figure skating project. I have a Person class and three subclasses: Skater, Coach and Choreographer.
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Person {
private String idPerson;
private String name;
private String sex;
private Calendar birthday;
private String info;
... getters and setters
}
@Entity
@PrimaryKeyJoinColumn(name="id_skater")
public class Skater extends Person {
private List<Result> resultsByIdSkater;
private List<SkaterCoach> skaterCoachesByIdSkater;
private List<SkaterCountry> skaterCountriesByIdSkater;
private List<SkaterChoreographer> skaterChoreographersByIdSkater;
...getters and setters
The coach and the choreographer are similar. It is obvious that a real person can simultaneously be a coach, choreographer and skater. I want to do something like this:
CoachDao coachDao=new CoachDaoImpl();
ChoreographerDao choreographerDao=new ChoreographerDaoImpl();
Coach coach= (Coach) coachDao.findByName("SERHII VAYPAN").get(0);
Choreographer choreographer= (Choreographer) choreographerDao.findByName("SERHII VAYPAN").get(0);
But I
org.hibernate.WrongClassException: Object [id=980ae71847e343f9a15755625456bf40] was not of the specified subclass [ru.fsinfo.entity.Coach] : loaded object was of wrong class class ru.fsinfo.entity.Choreographer
I understand that I can do this in different sessions. But for some reason I want to do it in one session. Is it possible?
+3
source to share
No one has answered this question yet
Check out similar questions: