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)
.
精彩评论