无法使用JPA更新实体,因为@OnetoOne依赖性属性是不可变的,但没有@Immutable注释
我想更新行:
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加
cascade = cascadetype.all
在您的实体关系中,它将使实体可变
Add
cascade=CascadeType.ALL
to your Entity relationShip in this relationShip, it will make the entity mutable
如果有效,请尝试
Try this if it works