如何使用空间注释? [英] How to use spatial annotation?

查看:115
本文介绍了如何使用空间注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在冬眠搜索中使用弹性搜索.我需要在kibana中构建图块地图.为此,我需要具有经度和纬度值的geo_point数据.我在冬眠中发现我们有@spatial注解做到这一点,但是当我使用的时候,我却遇到了异常.

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)

我有两个模型实体,我在下面写.我正在使用休眠搜索5.7.0.Final.

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;
    }
}

任何建议如何解决?

推荐答案

如我的评论中所述,NPE是一个错误: https://hibernate.atlassian.net/browse/HSEARCH-2858

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

我们应该很快修复它,但是即使上面的错误得到修复,仍然会存在另一个错误,并阻止您存储多值位置(单​​个"Actor"具有多个"ActorLocations"): https://hibernate.atlassian.net/browse/HSEARCH-2859 .不幸的是,该错误很难修复,我们可能需要等待主要版本.

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.

解决这两个问题的一种方法是反向索引嵌入:将actor嵌入到ActorLocations中,而不是相反.然后,针对ActorLocations而不是针对Actor执行所有搜索查询.我知道这不是理想的解决方案,但是应该可以.

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.

这篇关于如何使用空间注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆