使用Eclipselink 2.2.0映射继承时遇到问题。 这是我的抽象实体:
@Entity
@Inheritance(strategy= InheritanceType.SINGLE_TABLE)
public abstract class Feature extends TenantPossession {
private FeatureType featureType;
@Enumerated(EnumType.STRING)
public FeatureType getFeatureType() {
return featureType;
}
public void setFeatureType(FeatureType featureType) {
this.featureType = featureType;
}
}
子类看起来像这样:
@Entity
public class RecordingFeature extends Feature {
// here some attributes
}
当我第一次保存该功能时,它工作正常。但是当我尝试设置要素类型并保存它时,没有任何反应。
Feature feature = new RecordingFeature();
feature.setType(FeatureType.RECORDING);
feature = featureService.save(feature); // works fine
...提交事务并启动另一个事务......
feature.setType(FeatureType.UNKNOWN);
feature = featureService.save(feature); // seems to work, but type is not set in DB
它与继承有关吗?我在代码中有另一个没有继承的情况可以正常工作。
答案 0 :(得分:2)
save()有什么作用?确保您正在更改对象的托管版本,而不是分离的对象。
您是否启用了编织?如果禁用编织(更改跟踪)会发生什么?