How to use spatial annotation?

让人想犯罪 __ 提交于 2019-12-13 03:38:06

问题


I am using elastic search with hibernate search.I am having a requirement where I have to build tiles map in kibana.For that I need to have geo_point data with latitude and longitude value.I found in hibernate we have @spatial annotation to do this,but when I am using I am getting below exception.

java.lang.NullPointerException at org.hibernate.search.engine.metadata.impl.TypeMetadata$Builder.getAnalyzerReference(TypeMetadata.java:631)

I am having two model entity and I am writing it below.I am using hibernate search 5.7.0.Final.

@Entity
@Table(name = "actors", catalog = "twitter")
public class Actors implements java.io.Serializable {
    Set<ActorsLocation> actorsLocation;
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "actors")
    @Cascade(CascadeType.SAVE_UPDATE)
    @IndexedEmbedded
    public Set<ActorsLocation> getActorsLocation() {
        return actorsLocation;
    }
    public void setActorsLocation(Set<ActorsLocation> actorsLocation) {
        this.actorsLocation = actorsLocation;
    }
}
@Entity
@Spatial
@Table(name = "actors_location", catalog = "twitter")
public class ActorsLocation implements java.io.Serializable {
    private static final long serialVersionUID = 3585685166633868737L;
    Long id;
    @Id
    @Column(name = "id",nullable = false)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @Latitude
    @Field
    Double lat;
    @Longitude
    @Field
    Double lon;
    @ContainedIn
    Actors actors;
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)  
    public Actors getActors() {
        return actors;
    }
    public void setActors(Actors actors) {
        this.actors = actors;
    }
}

Any suggestion how to resolve it?


回答1:


As mentioned in my comment, the NPE is a bug: https://hibernate.atlassian.net/browse/HSEARCH-2858

We should fix it fairly quickly, but even if the bug above gets fixed, another one will still remain and prevent you from storing multi-valued locations (multiple "ActorLocations" for a single "Actor"): https://hibernate.atlassian.net/browse/HSEARCH-2859 . That bug is unfortunately harder to fix, we may need to wait for a major version.

One way to work around both issues would be to reverse index embedding: embed the actor in your ActorLocations and not the opposite. Then, execute all your search queries against ActorLocations and not against Actor. Not an ideal solution, I know, but it should work.



来源:https://stackoverflow.com/questions/45818907/how-to-use-spatial-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!