姬長信(Redy)

jpa – 相关对象的Eclipselink历史记录


我可以使用HistoryCustomizer创建实体的历史记录

@Entity
@Customizer(MyHistoryCustomizer.class)
public class Employee {..}

HistoryCustomizer就是这样的:

public class MyHistoryCustomizer implements DescriptorCustomizer {
    public void customize(ClassDescriptor descriptor) {
        HistoryPolicy policy = new HistoryPolicy();
        policy.addHistoryTableName("EMPLOYEE_HIST");
        policy.addStartFieldName("START_DATE");
        policy.addEndFieldName("END_DATE");
        descriptor.setHistoryPolicy(policy);
    }
}

可以使用“AS_OF”提示获取历史对象

javax.persistence.Query historyQuery = em
                    .createQuery("SELECT e FROM Employee e", Employee.class)
                    .setParameter("id", id)
                    .setHint(QueryHints.AS_OF, "yyyy/MM/dd HH:mm:ss.SSS")
                    .setHint(QueryHints.READ_ONLY, HintValues.TRUE)
                    .setHint(QueryHints.MAINTAIN_CACHE, HintValues.FALSE);

很好但是,如果你开始访问这个历史对象引用的对象,引用的对象将是它们的实际版本.因此,去年的员工(由历史查询提取)将分配当前的地址,而不是去年曾用过的地址.

如何告诉EclipseLink(2.5.0)从过去获取相关对象?