简体   繁体   English

AnnotationException:MappedBy通过引用未知的目标实体属性-映射继承的类

[英]AnnotationException: MappedBy reference an unknown target entity property - mapping an inherited class

I have such entities with inheritance 我有这样的继承实体

    @MappedSuperclass
    public class PostEntity {
    ...
        @ManyToOne
        @JoinColumn(name = "user_id")
        private UserEntity author;
    }

    @Entity
    @Table(name = "answers")
    public class AnswerEntity extends PostEntity {}

    @Entity
    @Table(name = "users")
    public class UserEntity {
    ...
        @OneToMany(mappedBy = "author", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
        private List<AnswerEntity> answers;
    }

during compilation, he throws me away 在编译过程中,他把我扔了

Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.example.demo.jpa.entity.AnswerEntity.author in com.example.demo.jpa.entity.UserEntity.answers

I do not know why he does not see the author field during mapping. 我不知道他为什么在映射过程中没有看到author字段。

It is not supported by JPA, at least not by Hibernate. JPA不支持它,至少Hibernate不支持。 You can either have: 您可以拥有:

@OneToMany(mappedBy = "author")
private List<PostEntity> answers;

Or move UserEntity author field to AnswerEntity. 或将UserEntity author字段移动到AnswerEntity。

暂无
暂无

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

相关问题 AnnotationException:mapped通过引用未知目标实体属性 - AnnotationException:mappedBy reference an unknown target entity property 错误:AnnotationException:mappedBy通过引用未知目标实体属性 - Error: AnnotationException: mappedBy reference an unknown target entity property org.hibernate.AnnotationException:mappedBy通过引用未知目标实体属性 - org.hibernate.AnnotationException: mappedBy reference an unknown target entity property java.lang.ExceptionInInitializerError和org.hibernate.AnnotationException:MapdBy引用了未知的目标实体属性: - java.lang.ExceptionInInitializerError and org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: 引起:org.hibernate.AnnotationException:mappedBy 引用了一个未知的目标实体属性 - Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property 调用init方法失败; 嵌套的异常是org.hibernate.AnnotationException:mappedBy引用了未知的目标实体属性: - Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: org.hibernate.AnnotationException:mappedBy引用未知的目标实体属性。 发生错误:java.lang.NullPointerException - org.hibernate.AnnotationException: mappedBy reference an unknown target entity property. There is an error: java.lang.NullPointerException OneToMany - org.hibernate.AnnotationException:mappedBy引用未知的目标实体属性 - OneToMany - org.hibernate.AnnotationException: mappedBy reference an unknown target entity property 通过引用继承继承的未知目标实体属性 - mappedBy reference an unknown target entity property with inheritance :mappedBy引用未知的目标实体属性 - : mappedBy reference an unknown target entity property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM