我使用spring 2.1、hibernate和mysql 8进行gis项目。
我有张有这个细节的桌子
@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属性的,以及如何用注释将空间索引添加到点。
发布于 2019-05-23 07:27:14
使用列定义尝试它。使用Hibernate 5.4.2和MySQL 8.0进行测试。
@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
https://stackoverflow.com/questions/53606441
复制相似问题