使用Eclipselink 2.2.0映射繼承時出現問題。 這裏是我的抽象的實體:JPA Eclipselink繼承:更新不起作用
@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
是否有事可做與繼承?我沒有繼承的代碼中的另一個案件工作正常。
不確定它是否有幫助,但在您的抽象類中嘗試@MappedSuperclass而不是'@Entity。 –
我已經想過,但在這種情況下,我需要每個子類的一個服務,並且搜索所有功能是不可能的。 =/ – santedicola
爲什麼你再次調用'save(feature)'方法?例如,如果您想更改'FeatureType',只需調用'update(feature)'方法即可。請提交'FeatureService'和'Entity'完整代碼。 – CycDemo