Store Geo-location details using play+jpa+mysql

786 views
Skip to first unread message

groovyUser

unread,
Jan 30, 2012, 12:47:59 AM1/30/12
to play-framework
Hello,

We are using play 1.2.2 and mysql. We need to store Geo-location of
the client based on some http requests. How do we do that using play
+jpa+mysql. MySQL has support for Spatial data types, how can I use
JPA to store data in this format?

thinker.612

unread,
Jan 30, 2012, 1:14:45 AM1/30/12
to play-framework
I am too having the same requirement. Can anybody guide?

The Thinker

unread,
Feb 3, 2012, 2:43:58 AM2/3/12
to play-framework
Got the solution.

We need following jar files:
hibernate-spatial-1.1.1.jar (New)
hibernate-spatial-mysql-1.1.1.jar (New)
jts-1.12.jar (New)

Now, we should declare the location property as following:

@Type(type="org.hibernatespatial.GeometryUserType")
@Column(columnDefinition="Point")
public com.vividsolutions.jts.geom.Point location;

That is it.
We have our property defined with proper JPA - Hibernet - SQL mapping.

How to create the object of com.vividsolutions.jts.geom.Point class is
also interesting.
It should be done as follows:

GeometryFactory factory = new GeometryFactory();
com.vividsolutions.jts.geom.Point point = factory.createPoint(new
Coordinate(longitude, latitude));

And we are good to go.

-- Cheers !!
Reply all
Reply to author
Forward
0 new messages