1

我在使用 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

跟继承有关系吗?我在没有继承的代码中还有其他情况可以正常工作。

4

1 回答 1

2

保存()做什么?确保您更改的是对象的托管版本,而不是分离的对象。

您是否启用了编织?如果禁用编织(更改跟踪)会发生什么?

于 2012-10-15T13:43:40.233 回答