Java Reference
In-Depth Information
@NamedQuery(name = "Item.findByItemId", 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;
@Basic(optional = false)
@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;
//generated constructors and 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 on 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.
The @OneToOne annotation is used to indicate a one-to-one relationship between
two JPA entities. Our schema doesn't have any one-to-one relationships between
tables, therefore this annotation was not added to any of the entities generated
by the wizard.
One-to-one relationships are not very popular in database
schemas. Nevertheless, JPA supports one-to-one relationships
in case it is necessary.
Search WWH ::

Custom Search