我正在使用eclipse链接Customizer来跟踪对表的更改:
@Entity
@Customizer(org.acme.persistence.HistoryCustomizer.class)
public class Employee{
@Id
private long id;
...
}
import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.history.HistoryPolicy;
public class HistoryCustomizer 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);
}
}
我的问题:有没有办法使用jpa(eclipse链接)获取此历史表,或者我必须创建一个虚拟实体才能搜索历史记录。
答案 0 :(得分:5)
是的,有:
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);
要注意的一些事情: