开发者

Geospatial support in JPA [duplicate]

This question already has answers here: PostGIS and JPA 2.0 开发者_Go百科 (3 answers) Closed 2 years ago.

How would I map point and polygon to java types. If this is not possible, what is a workaround?

I would like to use geospatial support in mysql or postgres through JPA.


I tried this too - you can get the data if you declare your field in JPA as a Byte[] and it will come down as a blob, but in MySQL spatial internal format - so no matter what, you'll always get an unreadable internal format - your best bet in JPA is to use a native SQL query to get the data down as text.

SELECT AsText(columnName) FROM tableName;

For instace:

String sql = "SELECT AsText(LOCATION) FROM ENTITY where id=?1";
return (String) em.createNativeQuery(sql)
                  .setParameter(1, id)
                  .getSingleResult();

returns in my case: POINT(40.01999 -75.147171).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜