Inserting a Point via JPA?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Inserting a Point via JPA?

jamo3

I'm having trouble using Hibernate Spatial in a JBoss JPA 1.0 container (JBoss 5.1 with Hiberante 3.3.1 and Spring 3.0.4) .  I got the HibernateSpatial tutorial working just fine including the JPA section, however the tutorial uses the hibernate Session object directly for persistence.  Standard JPA and all our code instead uses EntityManager objects for persistence - but the tutorial doesn't actually cover this method.   

I've defined an annotated location object in one of my pojo's as a Point (com.vividsolutions.jts.geom.Point): 

    @Type(type = "org.hibernatespatial.GeometryUserType")
    private Point location;

I set the point values via the following (I've actually tried it a couple of ways, but I liked this method):

GeometryFactory geomFact = new GeometryFactory(new PrecisionModel(), srid);
Coordinate coordinate = new Coordinate(latitude, longitude);
Point aPoint = geomFact.createPoint(coordinate);
track.setLocation(aPoint);

But when I commit the transaction (using EntityManager.getTransaction.commit()) I get the following error which contains an invalid insert statement (the insert is missing the call to the ST_GeometryFromText() function for the location column:

2012-06-07 15:56:25,728 ERROR [org.hibernate.util.JDBCExceptionReporter] (myJmsContainer-1) Batch entry 0 insert into myPointView (altitude, course, identity, lastUpdateDate, latitude, location, longitude, messageType, speed, timeSignature, msgQuality, version, msgNumber) values ('3925', '236', 'BAKER', '2012-06-07 15:56:25.660000 -06:00:00', '55.64746799227523',    'SRID=4326;POINT(-144.43648788284676 55.64746799227523)',    '-144.43648788284676', 'B14', '128', '2012-03-07 05:35:00.000000 -07:00:00', '7', '0', 'JJM217') was aborted.  Call getNextException to see the cause.

I see what the problem is, I just need to know what I'm doing wrong and how to fix it.  I can provide the spring setup, datasource setup, and peristence.xml files if needed.

Thanks in advance for your help.

Jay


_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Reply | Threaded
Open this post in threaded view
|

Re: Inserting a Point via JPA?

Karel Maesen
Administrator
Hi Jay,

I'll have a look at this.  But what you get is very strange:

On 08 Jun 2012, at 16:29, Jay Moss wrote:

>
> But when I commit the transaction (using EntityManager.getTransaction.commit()) I get the following error which contains an invalid insert statement (the insert is missing the call to the ST_GeometryFromText() function for the location column:
>
> 2012-06-07 15:56:25,728 ERROR [org.hibernate.util.JDBCExceptionReporter] (myJmsContainer-1) Batch entry 0 insert into myPointView (altitude, course, identity, lastUpdateDate, latitude, location, longitude, messageType, speed, timeSignature, msgQuality, version, msgNumber) values ('3925', '236', 'BAKER', '2012-06-07 15:56:25.660000 -06:00:00', '55.64746799227523',    'SRID=4326;POINT(-144.43648788284676 55.64746799227523)',    '-144.43648788284676', 'B14', '128', '2012-03-07 05:35:00.000000 -07:00:00', '7', '0', 'JJM217') was aborted.  Call getNextException to see the cause.
>
> I see what the problem is, I just need to know what I'm doing wrong and how to fix it.  I can provide the spring setup, datasource setup, and peristence.xml files if needed.
>

This is not how HS is implemented. The JTS geometries are serialized to an object that corresponds to the internal DB representation. So there is never in HS a call to a Geometry constructor function.

Could you provide details about your database setup: type and version of database, JDBC version and PostGIS version. Providing me with the set-up files, would be helpful. But if you could reproduce the problem with a variant of the tutorial code, that would be ideal for me because then I can investigate more fully the problem.

Regards,

Karel



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users