Hi,
I'm coming from Play 1.2 with Siena as ORM and am just in the process of moving to Play 2 with EBean. So I'm still a newbie to EBean.
I have the following requirements to my database tables:
- each of my tables shall have some change history information "createdOn", "lastChangeOn", ...
- some (most) of my tables will also have a column "tenant", since it's gonna be a multi-tenant system
So, coming from Siena, I just thought I can define my class hierarchy in Play 2 like this:
@MappedSuperclass
public class BaseModel extends Model {
@Id
public Long id;
public Date createdOn;
public Date lastChangeOn;
@ManyToOne
public User createdBy;
@ManyToOne
public User lastChangeBy;
// ...
}
@MappedSuperclass
public class TenantBaseModel extends BaseModel {
@Constraints.Required
@ManyToOne
public Tenant tenant;
}
The idea is basically, that I want to inherit my models for the tables without tenant from class BaseModel and the tables with tenant from class TenantBaseModel, e.g. like this:
@Entity
@Table(name="roles")
public class Role extends TenantBaseModel {
@Constraints.Required
@Formats.NonEmpty
public String name;
public String description;
}
When trying to run this app, I get the following runtime error:
PersistenceException: Error with [models.Role] It has not been enhanced but it's superClass [class models.TenantBaseModel] is? (You are not allowed to mix enhancement in a single inheritance hierarchy) marker[play.db.ebean.Model] className[models.Role]
So I'm just realizing that my naive approach might not fit EBean's concept. The tables for which I want to reuse the mapping code will be independent from each other. Obviously I don't want a single table for all my inherited models, and obviously I don't want a join table with a table holding some time stamps and the rest of my tables referencing there.
What is the best way to go here ?
Is it possible to use a common superclass for the timestamp fields at all ?
Or do I have to include these fields in each and every new model class mapping to a table ?
Thanks,
J.