I am triying to execute this query:
StringBuffer sb = new StringBuffer();
sb.append("select p from PointsEntity p " + "where within(p.coordinates,:polygon) = true");
But I have this exception:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.gisapp.springboot.backend.apirest.models.entity.PolygonEntity
This is the 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;
I have read a possible solution here but watching the entity, the solution has been already implemented in the UserEntity which contains the polygon´s collection:
@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;
Why do I have this exception?