2

I'm currently writing a new Java project with Play Framework 2.2.2 on Ubuntu. I'm attempting to set up a very simple class hierarchy that will allow the different db-persistable elements to inherit common fields, such as id, created_at, deleted_at etc, from one common BaseEntity class to avoid having to rewrite the same boiler plate.

The example I'm working with at the moment looks like this.

@Entity
public class User extends BaseEntity {

   @Id
   public int id;

   @Constraints.Required
   public String email;

   @Constraints.Required
   public IUser.Status status;

   public String activationCode;

   public User()
   {
    ...
   }
}

To exeriment I created a simple base class with one new attribute, name. This compiled fine:

@MappedSuperclass
public abstract class BaseEntity extends Model {

  protected String name;

  public String getName()
  {
    return this.name;
  }
  public void setName(String value)
  {
    this.name = value;
  }

  public BaseEntity()
  {

  }
}

Now, when the BaseEntity class didn't contain the name field or the getset-ers, EBean could successfully save the Entity to the db. Once I added the field with the getters and setters, when trying to save the entity Play crashed with the following exception:

java.lang.NoSuchMethodError: models.User._ebean_getni_name()Ljava/lang/String; at models.User._ebean_getField(User.java:1) at com.avaje.ebeaninternal.server.reflect.EnhanceBeanReflect$Getter.get(EnhanceBeanReflect.java:162) .....

Removing the getset-ers or moving them to the base class results in the same exception. I've looked pretty tirelessly online for examples that show what I'm doing wrong, but haven't found anything that fixes it. I'm sure it's something pretty simple. Can anyone help?

Regards.

mistakenot
  • 554
  • 3
  • 14

1 Answers1

2

This works for me. I'm not using getters or setters. I developed it on Play 2.2 and have it running on 2.3 now. I've removed most fields for clarity. It might be because you have the name field marked as protected?

@MappedSuperclass
public abstract class Member extends Model {

    @Id
    public Long id;
    public String businessName;
    public String webAddress;
..
}

@Entity
public class Supplier extends Member {

    public int minimumNoticeInHours;
    public int maximumNoticeInDays;
..
}
Shanness
  • 365
  • 2
  • 10
  • Thanks, I think it could be related to compiling problems - when I manually added the properties that it was missing e.g. _ebean_getni_name it compiled fine. I think that these are meant to be auto generated properties that for some reason weren't being generated properly for the base class. The access modifier made no difference. Have moved on to a simpler and less problematic ORM for the time being! – mistakenot Oct 06 '14 at 21:03