使用具有继承类型连接的Eclipselink历史策略

时间:2011-07-23 08:41:02

标签: inheritance jpa glassfish history eclipselink

我想使用eclipse链接历史记录将以下内容镜像到类

@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 {
    }

我的历史记录表是

@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 {
  }

,定制程序类是

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);
    }
}    

目前没有任何内容写入COMMESSIONEMPLOYEE_HISTORY表。我在这里做错了什么?

P,S>如果我使用单个表继承类EmployeeHistory,则不会将任何内容写入子类ComessionEmployeeHistorry的属性。

1 个答案:

答案 0 :(得分:0)

尝试自定义这两个类。

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);
    }
} 

但是,也记录一个错误,你的错误似乎不对。