mappedBy reference an unknown target entity property

后端 未结 3 1734
太阳男子
太阳男子 2020-11-29 20:02

I am having an issue in setting up a one to many relationship in my annotated object.

I have the following:

@MappedSuperclass
public abstract class M         


        
3条回答
  •  一个人的身影
    2020-11-29 20:45

    I know the answer by @Pascal Thivent has solved the issue. I would like to add a bit more to his answer to others who might be surfing this thread.

    If you are like me in the initial days of learning and wrapping your head around the concept of using the @OneToMany annotation with the 'mappedBy' property, it also means that the other side holding the @ManyToOne annotation with the @JoinColumn is the 'owner' of this bi-directional relationship.

    Also, mappedBy takes in the instance name (mCustomer in this example) of the Class variable as an input and not the Class-Type (ex:Customer) or the entity name(Ex:customer).

    BONUS : Also, look into the orphanRemoval property of @OneToMany annotation. If it is set to true, then if a parent is deleted in a bi-directional relationship, Hibernate automatically deletes it's children.

提交回复
热议问题