1
我嘗試在Play中使用Ebean的繼承!框架2.1.0。繼承策略是「單一表」,因爲它是唯一由Ebean支持的策略。我緊跟例如從JPA WikibookEbean繼承「沒有readMethod的抽象類」異常
@Entity
@Inheritance
@DiscriminatorColumn(name="price_type")
@Table(name="prices")
public abstract class Price {
@Id
public long id;
// Price value
@Column(precision=2, scale=18)
public BigDecimal value;
}
@Entity
@DiscriminatorValue("F")
public class FixedPrice extends Price {
// NO id field here
...
}
@Entity
@DiscriminatorValue("V")
public class VariablePrice extends Price {
// NO id field here
...
}
此代碼經過編譯,但我得到
RuntimeException: Abstract class with no readMethod for models.Price.id
com.avaje.ebeaninternal.server.deploy.ReflectGetter.create(ReflectGetter.java:33)
com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setBeanReflect(BeanDescriptorManager.java:1353)
com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createByteCode(BeanDescriptorManager.java:1142)
com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readDeployAssociations(BeanDescriptorManager.java:1058)
com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readEntityDeploymentAssociations(BeanDescriptorManager.java:565)
com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:252)
com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:124)
com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:210)
com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:64)
com.avaje.ebean.EbeanServerFactory.create(EbeanServerFactory.java:59)
play.db.ebean.EbeanPlugin.onStart(EbeanPlugin.java:79)
谷歌搜索帶來only one relevant link這是ReflectGetter.java的源代碼。註釋有說
對於持有我們需要使用反射來獲取ID值有時id屬性的抽象類。
這提供了BeanReflectGetter對象來做到這一點。
如果我從超類聲明中刪除abstract
關鍵字,則異常消失。我真的不想讓超類具體化。
我應該想到這一點。謝謝! – stys