use*_*368 43 java hibernate jpa
我收到以下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;
}
}
Run Code Online (Sandbox Code Playgroud)
简化的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;
}
}
Run Code Online (Sandbox Code Playgroud)
笔记:
任何人都可以阐明为什么会发生这种异常吗?
use*_*368 64
我想出了问题:我没有将类Team添加到Hibernate AnnotationConfiguration对象中.因此,Hibernate没有认识到这个类.
bvd*_*vdb 10
如果您将 Spring Boot 与 hibernate 结合使用,那么实际上您可能只需要将该包添加到您的@EntityScan基础包数组中即可。
@SpringBootApplication(scanBasePackages = {"com.domain.foo.bar.*"})
@EnableJpaRepositories(basePackages ={"com.domain.foo.bar.*"})
@EntityScan(basePackages ={"com.domain.foo.bar.*", "com.domain.another.*"})
public class SpringBootApplication extends SpringBootServletInitializer {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
64076 次 |
| 最近记录: |