无法使用JPA更新实体,因为@OnetoOne依赖性属性是不可变的,但没有@Immutable注释

发布于 2025-01-21 11:46:51 字数 1302 浏览 0 评论 0原文

我想更新行:

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

        geometryRepository.saveAll(values);
    }

但是它不起作用。

警告12400 --- [nio-8080-exec-8] ohpentity.abstractentitypersister:hhh000502:[com.samm.fiberplanner.entity.entity.gemetry.gemetry]实体的[功能]属性已修改,但不会修改由于属性是不可变的,因此可以更新。

复制实体:

@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;
}

为什么[功能]属性是不变的?如何更新表?

I want to update rows:

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

        geometryRepository.saveAll(values);
    }

But it does not work.

WARN 12400 --- [nio-8080-exec-8] o.h.p.entity.AbstractEntityPersister : HHH000502: The [feature] property of the [com.samm.fiberplanner.entity.Geometry] entity was modified, but it won't be updated because the property is immutable.

Releated entities:

@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;
}

Why is [feature] property is immutable? How can i update the table?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠佳期 2025-01-28 11:46:51

添加cascade = cascadetype.all在您的实体关系中

@OneToOne
@MapsId
private Feature feature;

,它将使实体可变

Add cascade=CascadeType.ALL to your Entity relationShip in this relationShip

@OneToOne
@MapsId
private Feature feature;

, it will make the entity mutable

一杆小烟枪 2025-01-28 11:46:51

如果有效,请尝试

@Entity(mutable = "true")

Try this if it works

@Entity(mutable = "true")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文