简体   繁体   English

Hibernate“ManyToOne ...引用未知实体”异常

[英]Hibernate “ManyToOne … references an unknown entity” exception

I just cannot get the relationship working between my two classes mapped to SQL tables with Hibernate. 我只是无法使用Hibernate将我的两个类映射到SQL表之间的关系。

The Role class: 角色类:

@Entity
@Table(name = "role")
public class Role {
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id")
    private int id;

    @Column(name="name")
    private String name;

    @OneToMany(mappedBy="memberinfo")
    private Set<Memberinfo> members;

    ...
}

And the Memberinfo class: 和Memberinfo类:

@Entity
@Table(name = "memberinfo")
public class Memberinfo {

    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id", nullable = false)
    private int id;

    @Column(name = "userid", nullable = false)
    private String userid;

    @Column(name = "email", nullable = false)
    private String email;

    @Column(name = "password", nullable = false)
    private String password;

    @Column(name = "salt", nullable = false)
    private String salt;

    @Column(name = "name", nullable = false)
    private String name;

    @Column(name = "address")
    private String address;

    @Column(name = "phonenum")
    private String phonenum;

    @ManyToOne(targetEntity=Role.class)
    @JoinColumn(name="role_id")
    private Role role;

    ...
}

When i try to fetch data from the DB, it connects, but throws an exception: "HTTP Status 500 - @OneToOne or @ManyToOne on model.Memberinfo.role references an unknown entity: model.Role". 当我尝试从数据库中获取数据时,它会连接,但会抛出异常:“HTTP状态500 - 模型上的@OneToOne或@ManyToOne.Memberinfo.role引用未知实体:model.Role”。

If i delete the variable "Role", then it works, and i can fetch the membership data, but i need the connection between the two tables, but in this case, the previously mentioned exception appears every time. 如果我删除变量“Role”,那么它可以工作,我可以获取成员资格数据,但我需要两个表之间的连接,但在这种情况下,每次都会出现前面提到的异常。

No other solutions on stackoverflow worked for me so far. 到目前为止,stackoverflow上没有其他解决方案对我有用。

Any idea what am i doing wrong? 知道我做错了什么吗?

The "unknown entity error" can be thrown if the class is not actually an Entity (not annotated whith javax.persistence @Entity) or if the persitence provider doesn't "know" the class (package not scanned). 如果类实际上不是实体(未注释whith javax.persistence @Entity)或者persitence提供者不“知道”类(包未扫描),则可以抛出“未知实体错误”。

Is the Role class imported in Memberinfo the correct one ? 在Memberinfo中导入的Role类是正确的吗? Maybe you are importing another Role class from another library. 也许您正在从另一个库导入另一个Role类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate @ManyToOne 引用了一个未知实体 - Hibernate @ManyToOne references an unknown entity org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne<entity> 引用一个未知实体 - org.hibernate.AnnotationException: @OneToOne or @ManyToOne on <entity> references an unknown entity @OneToOne 或 @ManyToOne 引用未知实体 - @OneToOne or @ManyToOne on references an unknown entity Java Hibernate org.hibernate.AnnotationException:@OneToOne或@ManyToOne <class> 引用未知实体: <class> - Java Hibernate org.hibernate.AnnotationException: @OneToOne or @ManyToOne on <class> references an unknown entity: <class> 由以下原因引起:org.hibernate.AnnotationException:XX上的@OneToOne或@ManyToOne引用了未知实体:YY - Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on XX references an unknown entity: YY com.hibernate.domain.Bee.honey上的@OneToOne或@ManyToOne引用未知实体 - @OneToOne or @ManyToOne on com.hibernate.domain.Bee.honey references an unknown entity org.hibernate.AnnotationException:entities.Ques#tion.examId 上的 @OneToOne 或 @ManyToOne 引用了一个未知实体:long - org.hibernate.AnnotationException: @OneToOne or @ManyToOne on entities.Ques#tion.examId references an unknown entity: long 不断获取 org.hibernate.AnnotationException: @OneToOne 或 @ManyToOne 引用未知实体:错误 - Constantly getting org.hibernate.AnnotationException: @OneToOne or @ManyToOne references an unknown entity: error JPA OneToMany ManyToOne @OneToOne或@ManyToOne在引用未知实体时: - JPA OneToMany ManyToOne @OneToOne or @ManyToOne on references an unknown entity: 未知实体休眠中的异常 - `Unknown entity` Exception in hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM