[英]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.