Java Reference
In-Depth Information
stayed within the EJB 3 standard the PendingOrder class, we would have to write
extra code to maintain an index field in PendingOrderLineItem and to explicitly
delete line items when they are removed from the collection.
The other option is to use the vendor-specific extensions we saw in
section 10.1.2. We can use the JB oss-specific @OrderColumn extension to tell JB oss to
automatically maintain the index of each line item. We can also use the Cascade-
Type.DELETE_ORPHAN extension to specify that a line item should be automatically
deleted when it is removed from the lineItems collection. Using these annotations
couples the code to the JB oss EJB 3 implementation, but it's better that writing
extra code. Listing 10.1 shows part of the source code for the PendingOrder class.
Listing 10.1
PendingOrder entity bean
B Defines mapping for class
@Entity(access = AccessType.FIELD)
@Table(name = "PENDING_ORDER")
public class PendingOrder implements Serializable {
C Configures
primary key field
@Id(generate = GeneratorType.AUTO)
private int id;
private int state = PendingOrder.NEW;
D Maps deliveryTime field
@Column(name="DELIVERY_TIME")
private Date deliveryTime;
E Maps restaurant field
@ManyToOne
@JoinColumn(name = "RESTAURANT_ID")
private Restaurant restaurant;
F Maps lineItems
@OneToMany(cascade = { CascadeType.ALL })
@JoinColumn(name = "PENDING_ORDER_ID")
@org.hibernate.annotations.IndexColumn
bbbbbb bb (name="MENU_ITEM_INDEX")
@org.hibernate.annotations.Cascade(
bb
org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<PendingOrderLineItem>
lineItems = new ArrayList<PendingOrderLineItem>();
G Maps coupon
@ManyToOne(cascade=CascadeType.PERSIST,
targetEntity=AbstractCouponImpl.class)
@JoinColumn(name = "COUPON_ID")
private Coupon coupon;
@Embedded( {
@AttributeOverride(name = "street1",
column = { @Column(name = "DELIVERY_STREET1") }),
@AttributeOverride(name = "street2",
H
Maps deliveryAddress,
paymentInformation
Search WWH ::




Custom Search