我正在做一个关于花样滑冰的项目。 我有一个Person类和三个子类:Skater,Coach和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
教练和舞蹈指导是相似的。 很明显,真正的人可以同时担任教练,舞蹈指导和滑板运动员。 我想做这样的事情:
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);
但我有
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
我知道我可以在不同的会话中完成。但出于某种原因,我想在一个会话中做到这一点。有可能吗?