【发布时间】:2019-07-02 09:09:47
【问题描述】:
我正在尝试执行这个查询:
StringBuffer sb = new StringBuffer();
sb.append("select p from PointsEntity p " + "where within(p.coordinates,:polygon) = true");
但我有这个例外:
org.hibernate.TransientObjectException:对象引用了一个未保存的瞬态实例 - 在刷新之前保存瞬态实例:com.gisapp.springboot.backend.apirest.models.entity.PolygonEntity
这是多边形实体:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "user_email")
private String userEmail;
@Column(name = "point_name")
private String pointName;
@Column(name = "coordinates")
private Polygon coordinates;
我已经阅读了一个可能的解决方案here,但观察实体,该解决方案已经在包含多边形集合的 UserEntity 中实现:
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private List<PointsEntity> pointsList;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private List<PolygonEntity> polygonsList;
为什么会有这个异常?
【问题讨论】:
-
该错误可能与您显示的查询无关。在同一事务中还进行了哪些其他更改?