Java “多对一”属性类型不应为“持久性实体”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32123723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:03:52  来源:igfitidea点击:

'Many To One' attribute type should not be 'Persistence Entity'

javahibernateintellij-idea

提问by vphilipnyc

I'm trying out IntelliJ IDEA and it's warning me of a Hibernate association that I don't quite understand.

我正在尝试 IntelliJ IDEA,它警告我一个我不太了解的 Hibernate 关联。

One Side:

一边:

@Entity
@Table(name = "MY_REQ_ASSIGNEE")
public class MyRequestAssignee extends BaseUser {
    //...
    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL}, mappedBy = "myRequestAssignee")
    private Collection<MyRequest> myRequests = new ArrayList<>();
    //...
}

Many Side:

多面:

@Entity
@Table(name = "MY_REQUEST")
public class MyRequest implements Persistable {

   //...
   @ManyToOne(fetch=FetchType.EAGER)
   @JoinColumn(name="ASSIGNEE_ID")
   private MyRequestAssignee myRequestAssignee;
   //...
}

(Persistableis just an interface that has the idproperty to make sure Hibernate has access to it.)

Persistable只是一个具有id确保 Hibernate 可以访问它的属性的接口。)

I see the MyRequestAssigneetype underlined in red and the message reads 'Many To One' attribute type should not be 'Persistence Entity'.Are there something wrong with my relationships?

我看到 带有MyRequestAssignee红色下划线的类型,消息显示'Many To One' attribute type should not be 'Persistence Entity'.我的关系有问题吗?

For a sanity check, I looked at this postand this posttoo.

为了进行完整性检查,我也查看了这篇文章这篇文章

采纳答案by Phil Carter

I found this to be caused by the child entity not being defined in hibernate.cfg.xml. The error message could be improved.

我发现这是由 hibernate.cfg.xml 中未定义的子实体引起的。错误信息可以改进。

回答by Travieso

This question is a bit old, but I just wanted to add that this can also be caused by a conflicting hibernate .hbm mapping file and JPA annotations. I ran into this error message when converting old mapping files to annotations and forgot to comment out one of the old mapping files.

这个问题有点老了,但我只想补充一点,这也可能是由冲突的休眠 .hbm 映射文件和 JPA 注释引起的。我在将旧映射文件转换为注释时遇到了此错误消息,但忘记注释掉旧映射文件之一。