Spring Boot 无法使用JPA更新实体,因为@onetoone相依属性是不可变的,但没有@immutable注解

qni6mghb  于 2022-12-04  发布在  Spring
关注(0)|答案(2)|浏览(154)

我要更新行:

@PutMapping(value = "/updateEdits")
    @Transactional
    public void updateGeometry(@RequestBody List<Geometry> values){

        geometryRepository.saveAll(values);
    }

但它不起作用。
警告12400 --- [nio-8080-exec-8]运行时实体。抽象实体持久性:HHH 000502:[com.samm.fiberplanner.entity.Geometry]实体的[feature]属性已修改,但由于该属性不可变,因此不会更新。
已发布的实体:

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class Geometry {
    @Id
    private Long gId;

    private String type;

    @Column(columnDefinition = "TEXT")
    private String coordinates;

    @OneToOne
    @MapsId
    private Feature feature;

}

@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
public class Feature {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long fId;
    private String type;
    @ToString.Exclude
    @OneToOne(mappedBy = "feature",cascade = CascadeType.ALL)
    private Properties properties;
    @ToString.Exclude
    @OneToOne(mappedBy = "feature",cascade = CascadeType.ALL)
    private Geometry geometry;
    @ToString.Exclude
    @ManyToOne
    @JoinColumn(name = "geo_json_id")
    private GeoJson geoJson;
}

为什么[feature]属性是不可变的?我如何更新表?

lskq00tm

lskq00tm1#

试试这个,如果有用的话

@Entity(mutable = "true")
x6h2sr28

x6h2sr282#

将cascade=CascadeType.ALL添加到此关系中的实体关系@OneToOne @MapsId私有要素功能;,它将使实体可变。

相关问题