Spring Boot JPA与Hibernate Spatial自引用导致循环

时间:2016-06-08 17:41:10

标签: java hibernate jackson spring-data-jpa postgis

我目前正在编写一个服务,我可以用一些数据存储地理空间点。我有一个“dataPoint”类,如下所示:

@Entity
@Table(name = "datapoint")
public class DataPoint {
    @Id
    int dataPoint_id;

    @Column(name = "body")
    String body;

    @Column(name = "location", columnDefinition = "Geometry")
    PGgeometry location;

    @Column(name = "deleted")
    boolean deleted;

    //Getters and Setters...

我正在尝试使用Spring Boot简单地通过API路径向PostGIS数据库添加包含一些信息的点。我已经构建了一个如下所示的控制器:

@RestController
@RequestMapping(value = "/dataPoint")
public class DataPointController {

    @Autowired
    private DataPointService myPointService;

    @RequestMapping(value = "/add/{body}/{latitude}/{longitude}/")
    public DataPoint addDataPoint(@PathVariable String body, @PathVariable double latitude, @PathVariable double longitude){
        DataPoint myPoint = new DataPoint();
        myPoint.setBody(body);
        PGgeometry geometry = new PGgeometry();
        try {
            geometry.setValue("POINT("+longitude +" " + latitude+")");
            geometry.setType("POINT");
            // Debugging Stuff
            System.out.println("GEOMETRY VALUE LOOK: {{{{ " + geometry.getValue() + "   " + geometry.getType());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        myPoint.setLocation(geometry);
        myPointService.saveDataPoint(myPoint);
        return myPoint;
    }

又与DataPointService相关联,saveDataPoint()只是作为public void saveDataPoint(DataPoint myPoint) { dataPointRepository.save(myPoint); } 看起来像这样的控制器之间的中间人:

DataPointRepository

@Repository public interface DataPointRepository extends JpaRepository<DataPoint, Integer> { } ,如下所示:

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Direct self-reference leading to cycle (through reference chain: com.testing.model.DataPoint["location"]->org.postgis.PGgeometry["geometry"]->org.postgis.Point["firstPoint"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.testing.model.DataPoint["location"]->org.postgis.PGgeometry["geometry"]->org.postgis.Point["firstPoint"])

但是,当我访问我的添加链接时,我收到此错误:

@JsonBackReference

我已经看到$('input[class="input-text"]').on('change', (event) => { event.preventDefault(); $('#checkout').removeAttr('disabled'); }); ... <button type="submit" className="btn" id="checkout" disabled>Checkout</button> 及其在一些示例中使用的对偶,然而,它已用于实体来回链接的情况,我在这里看不到,实际上,错误甚至看起来都不是循环的,所以这里发生了什么?

0 个答案:

没有答案