0

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.

sdfgsdgsgr
  • 95
  • 1
  • 1
  • 8

1 Answers1

0

It is not supported by JPA, at least not by Hibernate. You can either have:

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

Or move UserEntity author field to AnswerEntity.

user158037
  • 2,659
  • 1
  • 24
  • 27