首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在hibernate注释中设置srid

在hibernate注释中设置srid
EN

Stack Overflow用户
提问于 2018-12-04 05:48:25
回答 1查看 475关注 0票数 0

我使用spring 2.1、hibernate和mysql 8进行gis项目。

我有张有这个细节的桌子

代码语言:javascript
复制
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Place {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long Id;

    @Column(nullable = false, columnDefinition = "point")
    Point point;

    String tittle;
    String text;

    @Column(name = "created_date", nullable = false, updatable = false)
    @CreatedDate
    @JsonIgnore
    private long createdDate;

    @Column(name = "modified_date")
    @LastModifiedDate
    @JsonIgnore
    private long modifiedDate;

    @org.springframework.data.annotation.CreatedBy
    @JsonIgnore
    Long CreatedBy;

    @LastModifiedBy
    @JsonIgnore
    Long ModifiedBy;

    @ManyToOne(fetch=FetchType.LAZY,optional = false)
    @JoinColumn(name="city_id",nullable = false)
    @OnDelete(action = OnDeleteAction.CASCADE)
    private City city;
}

我想为点添加索引,但是mysql让我发出警告:

查询优化器不会使用列'point‘上的空间索引,因为该列没有SRID属性。考虑向列添加一个SRID属性。

我是如何用注释向点添加srid属性的,以及如何用注释将空间索引添加到点。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-23 07:27:14

使用列定义尝试它。使用Hibernate 5.4.2和MySQL 8.0进行测试。

代码语言:javascript
复制
@Entity
public class GeometryEntity {

  @Id
  @GeneratedValue
  private Long id;

  // only allow geometries with SRID 4326 and not null (be able to create spatial indexes)
  @Column(nullable = false, columnDefinition = "GEOMETRY SRID 4326")
  private Geometry geometry;

  private void setId(final Long id) {
    this.id = id;
  }

  public Long getId() {
    return id;
  }

  public void setGeometry(final Geometry geometry) {
    this.geometry = geometry;
  }

  public Geometry getGeometry() {
    return geometry;
  }

}

另见:https://dev.mysql.com/doc/refman/8.0/en/spatial-type-overview.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53606441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档