-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Update of multicolumn user type leads to SQLGrammarException
PostPosted: Sat Oct 27, 2012 9:31 am 
Beginner
Beginner

Joined: Tue Aug 10, 2004 8:59 am
Posts: 47
I have a GeoPoint class which contains two properties latitude and longitude. To store it with JPA I have created a GeoPointType which is a custom user type. This all works fine – I can both read and write GPS data from the MySQL database this way.

However, when trying to write a query for updating a GeoPoint, I have run into trouble. As an example, I have an entity Place which has a property called location which is a GeoPoint, so to update the location of a place I am trying to use this query:

Query updateLocationQuery = entityManager.createQuery(
"UPDATE Place p SET p.location = :location WHERE p.id = :placeId"
)
.setParameter("location", myGeoPoint)
.setParameter("placeId", placeId);

In the database the Place table has two columns latitude and longitude, and I was hoping that Hibernate would figure out how to get the latitude and longitude from the GeoPoint parameter and execute an update of these columns. Sadly, what I am seeing is this:

org.hibernate.exception.SQLGrammarException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' longitude=(55.723758697509766, 9.5314302444458) where id=3282502802948813353171' at line 1
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
...

So to me it looks as if Hibernate thinks the GeoPointType only uses a single database column for storing both the latitude and longitude, which is of course not correct. My custom type specifies that it needs two columns like this

@Override
public int[] sqlTypes() {return new int[]{DoubleType.INSTANCE.sqlType(), DoubleType.INSTANCE.sqlType()};}

So my question is: Why does Hibernate fail to realize that the custom type uses two columns and try to push both the lat and lon into the same column? Note that, on a regular persist of a new entity containing a GeoPoint everything works fine, and Hibernate does the right thing, so why does it not work for an update?

Thanks

Randahl


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.