簡體   English   中英

對象引用了一個未保存的臨時實例-使用休眠空間在刷新之前保存該臨時實例

[英]object references an unsaved transient instance - save the transient instance before flushing using hibernate spatial

我正在嘗試執行此查詢:

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

這是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;

我在這里閱讀了一個可能的解決方案但觀看該實體,該解決方案已在包含多邊形集合的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;

為什么會有這個例外?

最后,我使用了另一種使用內部方法的方法。

我創建了一個時態表和一個實體來保存多邊形,稍后我執行以下查詢:

StringBuffer sb = new StringBuffer();
        sb.append("select p from PointsEntity p, TempPolygonEntity t "
        + "where within(p.coordinates, t.coordinates) = true"); 

使用后將保存該多邊形,以后將其刪除。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM