我已经花了几个小时试图完成这项工作。我正在使用历史记录策略为我的一些表创建完整的历史记录。这是在抽象类中定义的。然后我有一个普通实体实现这个类并定义它的字段。然后我想使用一个从上层类继承的类,但它的表设置为历史表。效果很好,唯一的问题是,当我对历史表(lasso_warehandling_entry)进行查询时,它总是从历史实体(lasso_warehandling_entry_hist)返回结果。所以我添加了线descriptor.getInheritancePolicy().setShouldReadSubclasses(false); 我在某处读到,它应该可以解决我的问题。不幸的是,它没有。现在我总是收到以下消息:
Exception Description: The descriptor [RelationalDescriptor(dao.LassoWarehandlingEntry --> [DatabaseTable(lasso_warehandling_entry)])] has been set to use inheritance, but a class indicator field has not been defined.
When using inheritance, a class indicator field or class extraction method must be set.
Parent Descriptor: [RelationalDescriptor(org.rorotec.lasso.dao.LassoWarehandlingEntry --> [DatabaseTable(lasso_warehandling_entry)])]
Descriptor: RelationalDescriptor(dao.LassoWarehandlingEntry --> [DatabaseTable(lasso_warehandling_entry)])
由于我们为每个实体使用单独的表,因此使用指标字段没有多大意义。无论如何,我只是无法将这条消息带走。有人知道我应该如何解决这个问题吗?代码如下所示:
@MappedSuperclass
@Customizer(abstractDao.HistoryCustomizer.class)
public abstract class AbstractAuditedOzlEntity {
// defined the columns all the autited classes have
...
}
public class HistoryCustomizer implements DescriptorCustomizer {
public void customize(ClassDescriptor descriptor) {
HistoryPolicy policy = new HistoryPolicy();
policy.addHistoryTableName(descriptor.getTableName() + "_hist");
policy.addStartFieldName("start_date");
policy.addEndFieldName("end_date");
descriptor.setHistoryPolicy(policy);
// This here I added afterwards, as described in the text, and is the reason for the error message i get
descriptor.getInheritancePolicy().setShouldReadSubclasses(false);
}
}
@Entity
// when i define the inhertiancetype already in the abstract class, it doesn't seem to have any influence, so I added it here.
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@Table(name = "lasso_warehandling_entry")
public class LassoWarehandlingEntry extends AbstractAuditedOzlEntity implements Serializable {
// define the specific stuff of this table
...
}
@Entity
@Table(name = "lasso_warehandling_entry_hist")
@AttributeOverride(name="id", column=@Column(name="hist_id"))
public class LassoWarehandlingEntryHist extends LassoWarehandlingEntry {
...
// add the columns which only exist in the history tables like end_date
}