引起:org.hibernate.MappingException:无法确定类型:org.springframework.data.elasticsearch.core.geo.GeoPoint

时间:2016-12-26 08:22:18

标签: spring-boot jhipster spring-data-elasticsearch

我有一个Location实体,它在Spring启动和spring-data-elasticsearch项目中具有类型org.springframework.data.elasticsearch.core.geo.GeoPoint的属性,如下所示:

@Entity
@Table(name = "location")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "location")
public class Location implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Column(name = "name", nullable = false)
    private String name;

    @NotNull
    @Column(name = "country", nullable = false)
    private String country;

    @GeoPointField
    private GeoPoint location;
...

但是当我启动应用程序时,hibernate会抛出Caused by: org.hibernate.MappingException: Could not determine type for: org.springframework.data.elasticsearch.core.geo.GeoPoint。有办法解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

我使用String(更多here)表格中的坐标的"12.14, 34.53"表示,并使用@GeoPointField注释,并且有效。

@GeoPointField
private String location;

答案 1 :(得分:0)

您可以拥有自己的位置类,其中包含两个字段并使用

public class Location {
    private double lat; 
    private double lon; 

    public double getLat() {
        return lat;
    }
    public void setLat(double lat) {
        this.lat = lat;
    }
    public double getLon() {
        return lon;
    }
    public void setLon(double lon) {
        this.lon = lon;
    }
}

在您的Document类中,您可以像这样使用

    @GeoPointField
    private Location lastLocation;