background image

Cascade Operations in the order Application

<< Entity Mapped to Multiple Database Tables | Temporal Types in the order Application >>
<< Entity Mapped to Multiple Database Tables | Temporal Types in the order Application >>

Cascade Operations in the order Application

Cascade Operations in the order Application
Entities that have relationships to other entities often have dependencies on the existence of the
other entity in the relationship. For example, a line item is part of an order, and if the order is
deleted, then the line item should also be deleted. This is called a cascade delete relationship.
In order, there are two cascade delete dependencies in the entity relationships. If the Order to
which a LineItem is related is deleted, then the LineItem should also be deleted. If the Vendor to
which a VendorPart is related is deleted, then the VendorPart should also be deleted.
You specify the cascade operations for entity relationships by setting the cascade element in the
inverse (non-owning) side of the relationship. The cascade element is set to ALL in the case of
Order.lineItems
. This means that all persistence operations (deletes, updates, and so on) are
cascaded from orders to line items.
Here is the relationship mapping in Order:
@OneToMany(cascade=ALL, mappedBy=
"order")
public Collection<LineItem> getLineItems() {
return lineItems;
}
Here is the relationship mapping in LineItem:
@ManyToOne
public Order getOrder() {
return order;
}
BLOB and CLOB Database Types in the order
Application
The PARTDETAIL table in the database has a column, DRAWING, of type BLOB. BLOB stands for
binary large objects, which are used for storing binary data such as an image. The DRAWING
column is mapped to the field Part. drawing of type java.io.Serializable. The @Lob
annotation is used to denote that the field is large object.
@Column(table=
"EJB_ORDER_PART_DETAIL")
@Lob
public Serializable getDrawing() {
return drawing;
}
PARTDETAIL
also has a column, SPECIFICATION, of type CLOB. CLOB stands for character large
objects, which are used to store string data too large to be stored in a VARCHAR column.
The order Application
The Java EE 5 Tutorial · September 2007
718