Using Eclipselink history policy with inheritance type join
I would like to use eclipse link history to mirror the following to classes
@Entity
@Table(name="EMPLOYEE")
@Inheritance(strategy= InheritanceType.JOINED)
@TableGenerator(name="Employee_Gen", table="ID_GEN", pkColumnName="开发者_运维技巧GEN_NAME", valueColumnName="GEN_VAL", pkColumnValue="Employee_Gen")
@Customizer(EmployeeCustomizer.class)
public class Employee implements Serializable {
}
@Entity
@Table(name="COMMESSIONEMPLOYEE")
public class CommesionEmployee extends Employee {
}
where my history tables are
@Entity
@Table(name="EMPLOYEE_HISTORY")
@IdClass(EmployeeHistoryId.class)
@Inheritance(strategy= InheritanceType.JOINED)
public class EmployeeHistory implements Serializable {
}
@Entity
@Table(name="COMMISSIONEMPLOYEE_HISTORY")
public class CommesionEmployeeHistory extends EmployeeHistory {
}
and the customizer class is
public class EmployeeCustomizer implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor cd) throws Exception {
HistoryPolicy policy = new HistoryPolicy();
policy.addStartFieldName("MJSTART");
policy.addEndFieldName("EMPLOYEE.MJEND");
//policy.addEndFieldName("COMMISSIONEMPLOYEE.CEEND");
policy.addHistoryTableName("EMPLOYEE","EMPLOYEE_HISTORY");
//policy.addHistoryTableName("COMMISSIONEMPLOYEE","COMMISSIONEMPLOYEE_HISTORY");
policy.setShouldHandleWrites(true);
cd.setHistoryPolicy(policy);
}
}
Currently nothing is being written to the COMMESSIONEMPLOYEE_HISTORY table. What am I doing wrong here?
P,S> If I use single table for inheritance for class EmployeeHistory nothing will be written to properties of the subclass ComessionEmployeeHistorry.
Odd.
Try customizing both classes.
public class EmployeeCustomizer implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor cd) throws Exception {
HistoryPolicy policy = new HistoryPolicy();
policy.addStartFieldName("MJSTART");
policy.addEndFieldName("MJEND");
policy.addHistoryTableName("EMPLOYEE","EMPLOYEE_HISTORY");
policy.setShouldHandleWrites(true);
cd.setHistoryPolicy(policy);
}
}
public class CommesionEmployeeCustomizer implements DescriptorCustomizer {
@Override
public void customize(ClassDescriptor cd) throws Exception {
HistoryPolicy policy = new HistoryPolicy();
policy.addStartFieldName("MJSTART");
policy.addEndFieldName("MJEND");
policy.addHistoryTableName("COMMISSIONEMPLOYEE","COMMISSIONEMPLOYEE_HISTORY");
policy.setShouldHandleWrites(true);
cd.setHistoryPolicy(policy);
}
}
But, also log a bug, your errors don't seem right.
精彩评论