我正在尝试为项目中的所有模型实现基本模型,基类如下所示:
@MappedSuperclass
public class BaseModel extends Model {
private static final long serialVersionUID = 1658731911988408622L;
@CreatedTimestamp
public Date createdAt;
public Date updatedAt;
protected final void doBeforeSave() {
Date now = new Date();
createdAt = updatedAt = now;
beforeSave();
}
protected void beforeSave() {
}
@Override
@Transactional
public void save() {
doBeforeSave();
super.save();
}
}
这是子类扩展上面的BaseModel和客户端代码以保存订单到db:
@Entity
@Table(name = "orders")
public class Order extends BaseModel {
private static final long serialVersionUID = -97840064118194854L;
@Id
@Constraints.Min(10)
public Long id;
}
// save an order
Order order = new Order();
order.save()
执行'order.save'时,我收到以下异常。
java.lang.NoSuchMethodError: models.Order._ebean_getni_updatedAt()Ljava/util/Date;
at models.Order._ebean_getField(Order.java:1)
at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect$Getter.get(EnhanceBeanReflect.java:162)
at com.avaje.ebeaninternal.server.deploy.BeanProperty.getValue(BeanProperty.java:756)
at com.avaje.ebeaninternal.server.persist.dmlbind.BindableProperty.dmlBind(BindableProperty.java:78)
at com.avaje.ebeaninternal.server.persist.dmlbind.BindableProperty.dmlBind(BindableProperty.java:63)
at com.avaje.ebeaninternal.server.persist.dmlbind.BindableList.dmlBind(BindableList.java:56)
at com.avaje.ebeaninternal.server.persist.dml.InsertMeta.bind(InsertMeta.java:145)
at com.avaje.ebeaninternal.server.persist.dml.InsertHandler.bind(InsertHandler.java:110)
at com.avaje.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:79)
at com.avaje.ebeaninternal.server.persist.dml.DmlBeanPersister.insert(DmlBeanPersister.java:57)
at com.avaje.ebeaninternal.server.persist.DefaultPersistExecute.executeInsertBean(DefaultPersistExecute.java:66)
at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:448)
at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:478)
at com.avaje.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:331)
at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveEnhanced(DefaultPersister.java:306)
at com.avaje.ebeaninternal.server.persist.DefaultPersister.saveRecurse(DefaultPersister.java:276)
at com.avaje.ebeaninternal.server.persist.DefaultPersister.save(DefaultPersister.java:244)
at com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1610)
at com.avaje.ebeaninternal.server.core.DefaultServer.save(DefaultServer.java:1600)
at com.avaje.ebean.Ebean.save(Ebean.java:453)
at play.db.ebean.Model.save(Model.java:95)
at core.BaseModel.save(BaseModel.java:69)
at controllers.Orders.index(Orders.java:19)
订单实施 BaseModel ,它应该有 updatedAt 字段,但 order.save 以任何方式失败!< / p>