2016-12-26 40 views
0

我有一個Location實體,它在Spring引導和彈簧數據中具有類型org.springframework.data.elasticsearch.core.geo.GeoPoint的屬性-elasticsearch項目如下:引起:org.hibernate.MappingException:無法確定類型爲: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。任何方式來解決這個問題?

回答

0

我使用String代表座標"12.14, 34.53"(更多here@GeoPointField註釋和工作。

@GeoPointField 
private String location; 
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; 
    } 
} 

,並在你的文檔類,你可以使用這樣

@GeoPointField 
    private Location lastLocation; 
相關問題