Java Reference
In-Depth Information
return zipCode;
}
}
It consists of a single zipCode field, which is the primary key field. Defining this kind
of entity bean to wrap a primitive value is a pretty simple change, but it's a shame
that it's necessary. You might be used to doing it when developing with EJB 2 , but if
you have been using JDO or Hibernate it's an annoying change to make.
Implementing the Coupon entity bean
The final set of types we'll show how to persist is the Coupon class hierarchy, which
consists of the Coupon interface and the concrete subclasses that implement vari-
ous discount strategies. One of the great features of EJB 3 is that, unlike EJB 2 , it
supports inheritance. This means that in order to map the Coupon class hierarchy
to the COUPON table, we must simply introduce an abstract superclass—the same
change we made with Hibernate and JDO . This class implements the Coupon
interface and is extended by the concrete classes such as FreeShippingCoupon
and PercentageDiscountCoupon :
@Entity(access = AccessType.FIELD)
@Table(name = "COUPON")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE,
discriminatorType = DiscriminatorType.STRING)
@DiscriminatorColumn(name = "COUPON_TYPE")
public abstract class AbstractCouponImpl implements Coupon {
@Id(generate = GeneratorType.AUTO)
private int id = -1;
private String code;
protected AbstractCouponImpl() {
}
protected AbstractCouponImpl(String code) {
this.code = code;
}
public String getCode() {
BB return code;
}
public int getId() {
bb return id;
}
}
 
Search WWH ::




Custom Search