Java Reference
In-Depth Information
attribute must indicate the name of the primary key column on the owning side of
the relationship. The value of the inverseJoinColumns attribute of @JoinTable
has a similar role as its joinColumns attribute, except it indicates the corresponding
columns for the non-owning side of the relationship.
The side of the many-to-many relationship containing the above annotations is
said to be the owning side of the relationship, let's look at how the many-to-many
relationship is defined in the non-owning side of the relationship, which, in our case
is the Item JPA entity.
package com.ensode.jpa;
//Imports deleted for brevity
@Entity
@Table(name = "ITEM")
//Named queries deleted for brevity
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "ITEM_ID", nullable = false)
private Integer itemId;
@Column(name = "ITEM_NUMBER")
private String itemNumber;
@Column(name = "ITEM_SHORT_DESC")
private String itemShortDesc;
@Column(name = "ITEM_LONG_DESC")
private String itemLongDesc;
@ManyToMany(mappedBy = "itemIdCollection")
private Collection<CustomerOrder> customerOrderIdCollection;
//Constructors, getters, setters and other methods
//deleted for brevity.
}
As we can see, the only thing we need to do on this side of the relationship is to
create a Collection property, decorate it with the @ManyToMany annotation and
specify the property name in the other side of the relationship as the value of its
mappedBy attribute.
In addition to one-to-many and many-to-many relationships, it is possible to create
one-to-one relationships between JPA entities.
 
Search WWH ::




Custom Search