Spring Spatial Hibernate InvalidDefinitionException - PullRequest
0 голосов
/ 23 октября 2018

Я использую PostgreSQL с PostGIS для хранения геопространственных данных MultiPolygon

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

Я создал Entity, Repository и Controller в Spring Boot следующим образом:

Entity:

@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>

...