문제

I am trying to map an Address entity and a Person entity using a OneToMany mapping: "Each person has only one address but an Address can have many people".

@RooJavaBean
@RooToString
@RooEntity(identifierColumn = "addressID")
public class Address {

    @OneToMany(cascade = CascadeType.ALL, **mappedBy = "address**")
    private Set<Person> persons = new HashSet<Person>();
}

I cannot figure out what to map the Address entity with (bold), i have very little experience with JPA(Eclipse Link) and Spring roo but i thought the mappedBy should equal addressID and for a bidirectional ManyToOne on my Person entity mappedBy should equal personID?

도움이 되었습니까?

해결책

As any JPA docs would tell you (all JPA implementations provide them), mappedBy is the name of the field of type "Address" in Person class. If you don't have a field of that type in Person, then the relation is not bidirectional and so you don't use "mappedBy"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top