将ST_SetSRID(ST_MakePoint(?,?),4326)转换为Java @Entity

时间:2016-08-12 06:38:57

标签: spring geospatial

我有这个SQL语句(已经缩短了)

INSERT INTO incidents (lat, lon, geom)
VALUES (?, ?, ST_SetSRID(ST_MakePoint(?, ?), 4326));

模式

CREATE TABLE vessel_incidents
(
  id                 BIGSERIAL PRIMARY KEY,
  lat                DOUBLE PRECISION,
  lon                DOUBLE PRECISION,
  geom               GEOMETRY
);

由Java PreparedStatement使用:

1st ? = lat (Double)
2nd ? = lon (Double)
3rd ? = lat (Double)
4th ? = lon (Double)

这很好用但我们正在转向Spring这是我的实体。

@Entity
@Table(name = "incidents")
public class IncidentEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(nullable = false, unique = true, updatable = false)
    private Long id;

    private Double lat;

    private Double lon;

    @Column(name = "geom", columnDefinition = "GEOMETRY")
    private String geometry;
}

这是“0101000020E6100000ABAAAAAAAAAAA274000000000000013C0”栏的值(这就是我使用String的原因)

由于我们使用的是@Repository,如何创建几何字符串?目前的方式是使用

ST_SetSRID(ST_MakePoint(?, ?), 4326) in a java PreparedStatement.

是否有一个等同于ST_MakePoint和ST_SetSRID的java类,可以在@ Entity / @ Repository中使用?

感谢。

0 个答案:

没有答案