有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JPA Eclipselink继承:更新不起作用

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

这和遗产有关吗?我还有另外一个没有继承的代码案例可以很好地工作


共 (1) 个答案

  1. # 1 楼答案

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

    你们有纺织设备吗?如果禁用编织(更改跟踪),会发生什么情况