Inheritance with EBean

1,049 views
Skip to first unread message

J. O. Meyer

unread,
May 16, 2012, 4:38:16 PM5/16/12
to eb...@googlegroups.com
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.

Rob Bygrave

unread,
May 16, 2012, 6:35:10 PM5/16/12
to eb...@googlegroups.com
That error you are seeing is an Enhancement error - so you can't 'conclude' anything except that the Role class was not enhanced (I wonder if Role is in a separate jar or anything like that?). I think you should be able to do what you are trying.

You could 'convert' it to non-play java ... and use the normal Ebean enhancement, if that all worked then that would probably point the finger at the Play enhancement.


Cheers, Rob.

J. O. Meyer

unread,
May 18, 2012, 5:26:13 AM5/18/12
to eb...@googlegroups.com
Hi Rob,

thx for the reply. You were right, the issue was a missing configuration in Play.
I found a related discussion in the Play group:


Now it works.

J.
Reply all
Reply to author
Forward
0 new messages