Java Reference
In-Depth Information
The @Inheritance annotation defines the inheritance strategy for the Coupon class
hierarchy and specifies that the discriminator column, which identifies the type of
the instance, stores strings. The @DiscriminatorColumn annotation specifies that
the COUPON_TYPE column stores the type of the coupon.
Here is the FreeShippingCoupon class, which now extends AbstractCouponImpl
rather than implementing Coupon :
@Entity (access=AccessType.FIELD)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE,
discriminatorValue="FREE_SHIP")
public class FreeShippingCoupon extends Coupon {
private double minimum;
public FreeShippingCoupon() {
}
public FreeShippingCoupon(String code, double minimum) {
super(code);
this.minimum = minimum;
}
}
The discriminatorValue member of the @Inheritance annotation specifies that
the value of "FREE_SHIP" in the COUPON_TYPE column indicates that the row repre-
sents a FreeShippingCoupon . The other subclasses of Coupon are annotated in a
similar way.
Fields such as PendingOrder.coupon , which reference a Coupon , must be anno-
tated with an @ManyToOne annotation that specifies the referenced class as
AbstractCouponImpl :
Class PendingOrder {
@ManyToOne(cascade = CascadeType.PERSIST,
targetEntity = AbstractCouponImpl.class )
@JoinColumn(name = "coupon_id")
private Coupon coupon;
}
The targetEntity member specifies that the coupon field is really a reference to
an AbstractCouponImpl .
As you can see, entity beans are POJO s, but the limitations of the EJB 3 O/R
mapping requires some changes to the domain model and/or the use of vendor-
specific extensions. Table 10.1 summarizes these issues.
 
 
 
 
 
Search WWH ::




Custom Search