Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create a base model class in Play using Ebean

I am trying to create the following class in Play using Ebean:

public class BaseModel extends Model {

    @Column(name = "created_at")
    public Date createdAt;

    @Column(name = "updated_at")
    public Date updatedAt;

    @PrePersist
    public void createdAt() {
        this.createdAt = this.updatedAt = new Date();
    }

    @PreUpdate
    public void updatedAt() {
        this.updatedAt = new Date();
    }

}

It compiles fine no problem, but when I subclass this class with my entity beans (so each of them will insert timestamps for creation and update) I am getting the following exception when trying to hit the app:

play.api.UnexpectedException: Unexpected exception[PersistenceException: Error with [models.InventoryItem] I believe it is not enhanced but it's superClass [class models.BaseModel] is? (You are not allowed to mix enhancement in a single inheritance hierarchy)]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:150) ~[play_2.10.jar:2.1.4]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:114) ~[play_2.10.jar:2.1.4]
        at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:114) ~[play_2.10.jar:2.1.4]
        at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.1.4]
        at scala.util.Either$RightProjection.flatMap(Either.scala:523) ~[scala-library.jar:na]
Caused by: javax.persistence.PersistenceException: Error with [models.InventoryItem] I believe it is not enhanced but it's superClass [class models.BaseModel] is? (You are not allowed to mix enhancement in a single inheritance hierarchy)
        at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.setBeanReflect(BeanDescriptorManager.java:1374) ~[avaje-ebeanorm-server.jar:na]
        at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.createByteCode(BeanDescriptorManager.java:1142) ~[avaje-ebeanorm-server.jar:na]
        at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readDeployAssociations(BeanDescriptorManager.java:1058) ~[avaje-ebeanorm-server.jar:na]
        at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.readEntityDeploymentAssociations(BeanDescriptorManager.java:565) ~[avaje-ebeanorm-server.jar:na]
        at com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:252) ~[avaje-ebeanorm-server.jar:na]
        at com.avaje.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:124) ~[avaje-ebeanorm-server.jar:na]
like image 672
k9m Avatar asked Nov 04 '13 15:11

k9m


1 Answers

Try adding this annotation:

@MappedSuperclass
public class BaseModel extends Model {
...


}
like image 95
Juan Pedro Vargas Avatar answered Nov 08 '22 18:11

Juan Pedro Vargas