我对实现接口的抽象类有疑问。现在接口在我们的抽象类的实现中,而不是在其他实现中。我将在这里向您展示代码:
@MappedSuperclass
public abstract class AbstractOrder {
@Id
@GeneratedValue
private Long idOrder;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="datum")
private Date date = new Date();
@OneToMany(targetEntity=IOrderLine.class)
private List<IOrderLine> orderLines = new ArrayList<IOrderLine>();
private String refOrder;
...
}
@Entity
@Table(name="supplyorders")
public class SupplyOrder extends AbstractOrder implements Comparable<SupplyOrder>, Serializable {
@ManyToOne
private Supplier supplier;
@Enumerated(EnumType.STRING)
private SupplyOrderStatus status = SupplyOrderStatus.TOBESUPPLIED;
@ElementCollection
private Set<CustomerOrder> customerOrders = new HashSet<CustomerOrder>();
...
}
@Entity
@Table(name="customerorders")
public class CustomerOrder extends AbstractOrder implements commparable<CustomerOrder>,Serializable {
@ManyToOne
private Customer customer;
@ManyToOne
private Place place;
@ManyToOne
private User vendor;
private double deposit;
@Enumerated(EnumType.STRING)
private OrderStatus status = OrderStatus.CREATED;
}
@MappedSuperclass
public interface IOrderLine {
double getSubTotal();
int getQuantity();
Furniture getFurniture();
}
@Entity
@Table(name="supplyorderlines")
public class SupplyOrderLine implements IOrderLine, Serializable {
@Id
@GeneratedValue
private Long id;
@OneToMany
private List<CustomerOrderLine> customerOrderLines = new ArrayList<CustomerOrderLine>();
...
}
当然还有一个实现 IOrderLine 的类 CustormerOrderLine。
现在对于supplyOrder,他们有supplyOrderLines,customerOrder 有CustomerOrderLine。
我们得到的错误是抽象类不知道要对接口 IOrderLine 采取什么实现。
如何覆盖实现类中抽象类的 orderLines 字段,并用注解指向 IOrderLine 的实现?
提前谢谢。
寒冷世界