我收到以下hibernate异常:
@OneToOne or @ManyToOne on Matchup.awayTeam references an unknown entity: Team
简化的Matchup类如下所示:
@Entity public class Matchup implements Serializable { protected Team awayTeam; @ManyToOne @JoinColumn(name="away_team_id") public Team getAwayTeam() { return awayTeam; } }
简化的Team类如下所示:
@Entity public class Team implements Serializable { protected List<Matchup> matchups; @OneToMany(mappedBy="awayTeam", targetEntity = Matchup.class, fetch=FetchType.EAGER, cascade=CascadeType.ALL) public List<Matchup> getMatchups() { return matchups; } }
笔记:
谁能阐明为什么会发生这种异常?
我发现了问题:我没有将Team类添加到Hibernate AnnotationConfiguration对象中。因此,Hibernate无法识别该类。
AnnotationConfiguration