Pergunta

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?

Foi útil?

Solução

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"

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top