Java Reference
In-Depth Information
query = "SELECT i FROM Item i WHERE "
+ "i.itemId = :itemId"),
@NamedQuery(name = "Item.findByItemNumber",
query = "SELECT i FROM Item i WHERE "
+ "i.itemNumber = :itemNumber"),
@NamedQuery(name = "Item.findByItemShortDesc",
query = "SELECT i FROM Item i WHERE "
+ "i.itemShortDesc = :itemShortDesc"),
@NamedQuery(name = "Item.findByItemLongDesc",
query = "SELECT i FROM Item i WHERE "
+ "i.itemLongDesc = :itemLongDesc")})
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ITEM_ID")
private Integer itemId;
@Size(max = 10)
@Column(name = "ITEM_NUMBER")
private String itemNumber;
@Size(max = 100)
@Column(name = "ITEM_SHORT_DESC")
private String itemShortDesc;
@Size(max = 500)
@Column(name = "ITEM_LONG_DESC")
private String itemLongDesc;
@ManyToMany(mappedBy = "itemCollection")
private Collection<CustomerOrder> customerOrderCollection;
//constructors, getters, setters, equals() and hashCode()
//methods omitted 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