@OneToMany mappedBy maps to _____

Yes wrapper for javax.mail.Header is needed, in general you cannot persist directly arbitrary classes, especially not the ones that are not Serializable. Also they cannot be elements of list that designs relationship between entities.

Value of mappedBy is name of the field that is owning side of bidirectional relationship. For a sake of example, let’s assume that Article entity does have one-to-many relationship to Foo entity:

@OneToMany(mappedBy="article")
private List<Foo> headers;

Now we know that there must be other end of this relationship, and it is attribute, which is located to Foo entity, does have Article as a type and is named article:

@Entity
public class Foo {
...
   @ManyToOne
    Article article;
}

Owning side (in this case article in Foo) is used when bidirectional relationship is persisted to the database. In JPA 2.0 specification this is told with following words:

Bidirectional relationships between managed entities will be persisted
based on references held by the owning side of the relationship. It is
the developer’s responsibility to keep the in-memory references held
on the owning side and those held on the inverse side consistent with
each other when they change. In the case of unidirectional one-to-one
and one-to-many relationships, it is the developer’s responsibility to
insure that the semantics of the relationships are adhered to.

Leave a Comment