If I have one level of inheritance, everything is persisted as expected in App Engine:
Worker.java
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class Worker {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String department;
}
Employee.java
// ... imports ...
@PersistenceCapable
public class Employee extends Worker {
@Persistent
private int salary;
}
Intern.java
import java.util.Date;
// ... imports ...
@PersistenceCapable
public class Intern extends Worker {
@Persistent
private Date internshipEndDate;
}
However, if I add one additional layer of inheritance, the fields in the highest level subclass are not persisted:
Human.java
@PersistenceCapable
public abstract class Human {
@Persistent
private String name;
}
Worker.java
@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE)
public abstract class Worker extends Human {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String department;
}
And your Primary key is now not in the root class of the (persistable) inheritance tree, hence invalid by the JDO and JPA specs.