我开了一个Auction.java课,因为我已经添加了一种新的Bid(Ducth one)并且创建了一个抽象类Bid.java--@Entity @Inheritance(strategy = InheritanceType .JOINED)(EnglishBid和DucthBid扩展抽象Bid类并有自己的方法isHighter / isLower)我得到这个错误(当我想添加一个新的拍卖(在前端使用JSF)并使用EntityManager保存到DB中): / p>
javax.faces.el.EvaluationException: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
这是Auction.java(@ Names,@ ViewScoped):
private AbstractBid highestBid; //One to One RELATIONSHIP + CASCADE=ALL
private List<AbstractBid> bids = new ArrayList<AbstractBid>();
@OneToMany(cascade = ALL, fetch = FetchType.EAGER, mappedBy = "auction")
@Column(nullable = true, updatable = false)
@OrderBy("amount DESC")
public List<AbstractBid> getBids() {
return bids;
}
public void setBids(List<AbstractBid> bids) {
this.bids = bids;
}
public void addBid(AbstractBid bid) {
if(bid instanceof EnglishBid)
{
if (!((EnglishBid) bid).isHigher(originalPrice)) {
throw new IllegalArgumentException("The new bid ("
+ ((EnglishBid) bid).getAmount()
+ ") have to be greater than original price ("
+ originalPrice + ")");
}
if (!((EnglishBid) bid).isHigher((EnglishBid) highestBid)) {
throw new IllegalArgumentException("The new bid ("
+ ((EnglishBid) bid).getAmount()
+ ") have to be greater than original price ("
+ ((EnglishBid) highestBid).getAmount() + ")");
}
this.getBids().add(bid);
this.setHighestBid(bid);
}
else
if(bid instanceof DutchBid)
{
if (!((DutchBid) bid).isLower(originalPrice)) {
throw new IllegalArgumentException("The new bid ("
+ ((DutchBid) bid).getAmount()
+ ") have to be lower than original price ("
+ originalPrice + ")");
}
if (!((DutchBid) bid).isLower((DutchBid) highestBid)) {
throw new IllegalArgumentException("The new bid ("
+ ((DutchBid) bid).getAmount()
+ ") have to be lower than hightestBid ("
+ ((DutchBid) highestBid).getAmount() + ")");
}
this.getBids().add(bid);
this.setHighestBid(bid);
}
}
和AbstractBid.java:
public AbstractBid(User bidder, Auction auction, Long amount) {
this.bidder = bidder;
this.auction = auction;
this.amount = amount;
auction.addBid(this);
}
这两个类都实现了Serializable,并且具有@Id @GeneratedValue。
任何想法的人吗?