Generic MappedSuperclass
dunks80 Feb 10, 2006 9:10 AMIs there anyway to use a generic class as a mappedsuperclass? I have an abstract class Shipment which looks something like this...
@MappedSuperclass public abstract class Shipment<ShipmentItemType extends ShipmentItem> extends Entity { protected List<ShipmentItemType> shippedItems; @OneToMany( fetch = FetchType.LAZY, mappedBy = "shipment", cascade = { CascadeType.PERSIST, CascadeType.MERGE }) public List<ShipmentItemType> getShippedItems() { return shippedItems; } public void setShippedItems(List<ShipmentItemType> shippedItems) { this.shippedItems = shippedItems; } }
then i have a subclass ColorBreakShipment that looks something like this...
@Entity @Table(name = "colorBreakShipment") public class ColorBreakShipment extends Shipment<ColorBreakShipmentItem> { /** * */ private Manufacturer manufacturer; // attributes public ColorBreakShipment() { super(); } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "manufacturerId") public Manufacturer getManufacturer() { return manufacturer; } public void setManufacturer(Manufacturer manufacturer) { this.manufacturer = manufacturer; } @OneToMany(targetEntity=ColorBreakShipmentItem.class, fetch = FetchType.LAZY, mappedBy = "shipment", cascade = { CascadeType.PERSIST, CascadeType.MERGE }) public List<ColorBreakShipmentItem> getShippedItems() { return super.getShippedItems(); } public void setShippedItems(List<ColorBreakShipmentItem> shippedItems) { super.setShippedItems(shippedItems); } }
However when I try to test the class i get the following exception...
... org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: entity.ColorBreakShipment.shippedItems ...
I even tried defining the get and set ShippedItems method in the super class as abstract methods but that didn't work either.
Does anyone know if there is anyway to use the generic class as a mapped superclass or do I just have to duplicate the fields in all "Shipment" classes