Hibernate @ManyToOne引用了一个未知的实体 [英] Hibernate @ManyToOne references an unknown entity

查看:187
本文介绍了Hibernate @ManyToOne引用了一个未知的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下Hibernate异常:



MatchO.awayTeam上的@OneToOne或@ManyToOne引用未知实体:Team $ b

简化的Matchup类看起来像这样:

  @Entity public class Matchup实现Serializable 
{
protected team awayTeam;

@ManyToOne
@JoinColumn(name =away_team_id)
public Team getAwayTeam(){
return awayTeam;




$ b

简化的Team类看起来像这样:

  @Entity 
public class Team implements Serializable {
protected List< Matchup>对决;

@OneToMany(mappedBy =awayTeam,targetEntity = Matchup.class,
fetch = FetchType.EAGER,cascade = CascadeType.ALL)
public List< Matchup> getMatchups(){
返回匹配;


$ / code $ / pre
$ b $注意:


  • Matchup和Team都有子类。我不确定这是否会影响这种情况。

  • 包含
    的Matchup和Team都列在我的persistence.xml中。

  • 如果我在两个getter方法中都放置了@Transient注解,那么错误
    就会消失。



任何人都可以阐明为什么这个异常正在发生?

解决方案

我想出了问题:我没有将类Team添加到Hibernate AnnotationConfiguration 对象。因此,Hibernate没有认识到这个类。

I am receiving the following Hibernate Exception:

@OneToOne or @ManyToOne on Matchup.awayTeam references an unknown entity: Team

The simplified Matchup class looks like this:

@Entity public class Matchup implements Serializable 
{
   protected Team awayTeam;

   @ManyToOne 
   @JoinColumn(name="away_team_id")
   public Team getAwayTeam() {
      return awayTeam;
   }
}

The simplified Team class looks like this:

@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;
    }
}

Notes:

  • Both Matchup and Team have subclasses. I'm not sure if this impacts the situation.
  • Both Matchup and Team are listed in my persistence.xml as being included.
  • If I put @Transient annotations on both getter methods, the error disappears.

Can anybody shed light on why this exception is occurring?

解决方案

I figured out the problem: I was not adding class Team to the Hibernate AnnotationConfiguration object. Thus, Hibernate was not recognizing the class.

这篇关于Hibernate @ManyToOne引用了一个未知的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆