I'm trying to understand how does the inheritance work in play! But unsuccessfully yet.
So, I have such superclass:
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
abstract class SuperClass extends Model {
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "SEQ_TABLE")
@TableGenerator(name = "SEQ_TABLE")
Long id;
int testVal;
}
And 2 inherited classes:
@Entity
public class Sub extends SuperClass {
String name;
@Override
public String toString() {
return name;
}
}
@Entity
public class Sub1 extends SuperClass {
String name;
@Override
public String toString() {
return name;
}
}
Also I have 2 controllers for inherited classes:
public class Subs and Sub1s extends CRUD {
}
After application was started, I recieve 2 tables in MySQL db for my models (Sub and Sub1) with such structure: id bigint(20), name varchar(255). Without testVal which is in superclass.
And when I try to create new object of Sub class in CRUD interface I recieve such error: Execution error occured in template {module:crud}/app/views/tags/crud/form.html. Exception raised was MissingPropertyException : No such property: testVal for class: models.Sub.
In {module:crud}/app/views/tags/crud/form.html (around line 64) #{crud.numberField name:field.name, value:(currentObject ? currentObject[field.name] : null) /}
- What should I do to generate MySQL tables for inherited models properly and fix the error?
- Is it possible to have a single superController for several inherited classes?
Well, thanks to sdespolit, I've made some experiments. And here is what I've got:
Superclass:
Inherited class:
"Super Controller" I made in such way:
@CRUD.For(Sub.class) is used to tell the interceptors with what class it should work
I'm not sure about doSomething() approach is truly nice and Java-style/Play!-style. But it works for me. Please tell me if it's possible to catch out the model's class in more native way.
"and table per class is an optional feature of the JPA spec, so not all providers may support it" from WikiBook.
Why don't you use @MappedSuperclass? Furthermore you should extend GenericModel. In your example you defined id twice, which could be the reason of you problem too.