Spring Spatial Hibernate InvalidDefinitionException

时间:2018-10-23 12:31:37

标签: java hibernate spring-boot persistence postgis

我将PostgreSQL与PostGIS一起使用来存储MultiPolygon地理空间数据

CREATE TABLE voivodeships
(
  id       INTEGER NOT NULL CONSTRAINT geotable_new_pk PRIMARY KEY,
  name     VARCHAR,
  geometry GEOMETRY(MultiPolygon, 4326);

我在Spring Boot中创建了实体,存储库和控制器,如下所示:

实体:

@Entity
@Table(name = "voivodeships")
public class Voivodeship {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank
    private String name;

    @Column
    private MultiPolygon geometry;

// getters and setters omitted

}

存储库:

public interface VoivodeshipRepository extends JpaRepository<Voivodeship, Long> { }

控制器:

@RestController
public class VoivodeshipController {

    @Autowired
    VoivodeshipRepository voivodeshipRepository;

    @GetMapping("/voiv/{id}")
    public Voivodeship getVoivodeshipById(@PathVariable(value = "id") Long id) {
        return voivodeshipRepository.findById(id).orElseThrow(()->new ResourceNotFoundException("Voivodeship " + id + " not found"));
    }
}

但是在localhost:8080/voiv/1上我得到了:

nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle

完全例外:

<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Oct 23 14:26:44 CEST 2018</div><div>There was an unexpected error (type=Internal Server Error, status=500).</div><div>Type definition error: [simple type, class org.geolatte.geom.crs.AngularUnit]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle (through reference chain: com.kswr.spring.boot.postgis.demo.postgisdemo.model.Voivodeship[&quot;geometry&quot;]-&gt;org.geolatte.geom.MultiPolygon[&quot;coordinateReferenceSystem&quot;]-&gt;org.geolatte.geom.crs.Geographic2DCoordinateReferenceSystem[&quot;coordinateSystem&quot;]-&gt;org.geolatte.geom.crs.EllipsoidalCoordinateSystem2D[&quot;axes&quot;]-&gt;org.geolatte.geom.crs.GeodeticLongitudeCSAxis[0]-&gt;org.geolatte.geom.crs.GeodeticLongitudeCSAxis[&quot;unit&quot;]-&gt;org.geolatte.geom.crs.AngularUnit[&quot;fundamentalUnit&quot;]-&gt;org.geolatte.geom.crs.AngularUnit[&quot;fundamentalUnit&quot;])</div></body></html>

0 个答案:

没有答案