Failed to load spatial(Geometry) data MySQL

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

Failed to load spatial(Geometry) data MySQL

Sergey21
I am using MySql, Hibernate 4 and hibernate-spatial-4.0-M1. I tried simply save and load entity, saving was successfull but loading throws exception:

java.lang.ClassCastException: java.lang.String cannot be cast to [B
        at org.hibernate.spatial.dialect.mysql.MySQLGeometryValueExtractor.toJTS(MySQLGeometryValueExtractor.java:47)
        at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
        at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
        at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
        at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
        at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2704)
        at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
        at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
        at org.hibernate.loader.Loader.getRow(Loader.java:1373)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
        at org.hibernate.loader.Loader.doQuery(Loader.java:850)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
        at org.hibernate.loader.Loader.doList(Loader.java:2438)
        at org.hibernate.loader.Loader.doList(Loader.java:2424)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
        at org.hibernate.loader.Loader.list(Loader.java:2249)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
        at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
        at com.mm.dao.hibernate.GeoDAO.getById(GeoDAO.java:33)
        at com.mm.service.GeoService.getById(GeoService.java:24)
        at com.mm.service.GeoService$$FastClassByCGLIB$$aeb6c7aa.invoke(<generated>)
        at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
        at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
        at com.mm.service.GeoLocationService$$EnhancerByCGLIB$$f879610f.getById(<generated>)
        at com.mm.controllers.GeoController.updateGeodata(GeoController.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHa
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingH
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandle
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

My entity:
publicclassGeoEntityimplements java.io.Serializable{
private Integer id;
private Point geom;
//...
}

entity hbm.xml
<propertyname="geom"type="org.hibernate.spatial.GeometryType">
<column
name="geom"sql-type="Geometry"not-null="true"/>
</property>
hibernate config:
<?xml version="1.0" encoding="UTF-8"?>
<beans     xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
               ">

    <context:property-placeholder location="/WEB-INF/classes/jdbc.properties" />
   
    <tx:annotation-driven transaction-manager="transactionManager" />    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingDirectoryLocations" value="classpath:com/test/m/mapping"/>
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect</prop>
            <prop key="show_sql">false</prop>
            <prop key="hibernate.order_updates">true</prop>
            <prop key="hibernate.globally_quoted_identifiers">true</prop>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
            <prop key="hibernate.default_catalog">${app.jdbc.dbname}</prop>
        <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>      
          </props>
        </property>
    </bean>

    <!-- Declare a datasource that has pooling capabilities-->    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                destroy-method="close"
                p:driverClass="${app.jdbc.driverClassName}"
                p:jdbcUrl="${app.jdbc.url}"
                p:user="${app.jdbc.username}"
                p:password="${app.jdbc.password}"
                p:acquireIncrement="${dataSource.acquireIncrement}"
                p:idleConnectionTestPeriod="${dataSource.idleConnectionTestPeriod}"
                p:maxPoolSize="${dataSource.maxPoolSize}"
                p:maxStatements="${dataSource.maxStatements}"
                p:minPoolSize="${dataSource.minPoolSize}"
                p:initialPoolSize="${dataSource.initialPoolSize}"/>

    <!-- Declare a transaction manager-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
                   p:sessionFactory-ref="sessionFactory" />
 
    <context:component-scan base-package="com.test.dao"/>
    <context:annotation-config/>
</beans>
load
(GeoEntity)sessionFactory.getCurrentSession().createQuery("from GeoEntity where id=:id")
.setInteger("id", id).uniqueResult();


_______________________________________________
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: Failed to load spatial(Geometry) data MySQL

Karel Maesen
Administrator
Hi Sergey,

Could you have a look in the database table and check the contents of the mapped table? What is the table schema?  Looks like JDBC is returning a String for the column geom, rather than a Geometry which is normally a varbinary.

Regards,

Karel
On 07 Dec 2012, at 13:37, Sergey wrote:

> I am using MySql, Hibernate 4 and hibernate-spatial-4.0-M1. I tried simply save and load entity, saving was successfull but loading throws exception:
>
> java.lang.ClassCastException: java.lang.String cannot be cast to [B
>         at org.hibernate.spatial.dialect.mysql.MySQLGeometryValueExtractor.toJTS(MySQLGeometryValueExtractor.java:47)
>         at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
>         at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
>         at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
>         at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
>         at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
>         at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
>         at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2704)
>         at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
>         at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
>         at org.hibernate.loader.Loader.getRow(Loader.java:1373)
>         at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
>         at org.hibernate.loader.Loader.doQuery(Loader.java:850)
>         at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
>         at org.hibernate.loader.Loader.doList(Loader.java:2438)
>         at org.hibernate.loader.Loader.doList(Loader.java:2424)
>         at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
>         at org.hibernate.loader.Loader.list(Loader.java:2249)
>         at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
>         at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
>         at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
>         at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
>         at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
>         at com.mm.dao.hibernate.GeoDAO.getById(GeoDAO.java:33)
>         at com.mm.service.GeoService.getById(GeoService.java:24)
>         at com.mm.service.GeoService$$FastClassByCGLIB$$aeb6c7aa.invoke(<generated>)
>         at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
>         at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
>         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
>         at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
>         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
>         at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
>         at com.mm.service.GeoLocationService$$EnhancerByCGLIB$$f879610f.getById(<generated>)
>         at com.mm.controllers.GeoController.updateGeodata(GeoController.java:48)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:601)
>         at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
>         at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
>         at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHa
>         at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingH
>         at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandle
>         at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
>         at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
>         at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
>         at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
>         at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
>         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
>         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
>         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
>         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
>         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
>         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
>         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
>         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
>         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
>         at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
>         at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
>         at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
>         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
>         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
>         at java.lang.Thread.run(Thread.java:722)
>
> My entity:
> publicclassGeoEntityimplements java.io.Serializable{
>  private Integer id;
>  private Point geom;
>  //...
> }
>
> entity hbm.xml
> <propertyname="geom"type="org.hibernate.spatial.GeometryType">
>    <columnname="geom"sql-type="Geometry"not-null="true"/>
> </property>
> hibernate config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans     xmlns="http://www.springframework.org/schema/beans"
>            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>            xmlns:p="http://www.springframework.org/schema/p"
>            xmlns:tx="http://www.springframework.org/schema/tx"
>            xmlns:context="http://www.springframework.org/schema/context"
>            xsi:schemaLocation="
>             http://www.springframework.org/schema/beans 
>             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>             http://www.springframework.org/schema/tx 
>             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
>             http://www.springframework.org/schema/context
>             http://www.springframework.org/schema/context/spring-context-3.0.xsd
>                ">
>
>     <context:property-placeholder location="/WEB-INF/classes/jdbc.properties" />
>    
>     <tx:annotation-driven transaction-manager="transactionManager" />    
>     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
>         <property name="dataSource" ref="dataSource"/>
>         <property name="mappingDirectoryLocations" value="classpath:com/test/m/mapping"/>
>         <property name="hibernateProperties">
>           <props>
>             <prop key="hibernate.dialect">org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect</prop>
>             <prop key="show_sql">false</prop>
>             <prop key="hibernate.order_updates">true</prop>
>             <prop key="hibernate.globally_quoted_identifiers">true</prop>
>             <prop key="hibernate.hbm2ddl.auto">validate</prop>
>             <prop key="hibernate.default_catalog">${app.jdbc.dbname}</prop>
>         <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>      
>           </props>
>         </property>
>     </bean>
>
>     <!-- Declare a datasource that has pooling capabilities-->    
>     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
>                 destroy-method="close"
>                 p:driverClass="${app.jdbc.driverClassName}"
>                 p:jdbcUrl="${app.jdbc.url}"
>                 p:user="${app.jdbc.username}"
>                 p:password="${app.jdbc.password}"
>                 p:acquireIncrement="${dataSource.acquireIncrement}"
>                 p:idleConnectionTestPeriod="${dataSource.idleConnectionTestPeriod}"
>                 p:maxPoolSize="${dataSource.maxPoolSize}"
>                 p:maxStatements="${dataSource.maxStatements}"
>                 p:minPoolSize="${dataSource.minPoolSize}"
>                 p:initialPoolSize="${dataSource.initialPoolSize}"/>
>
>     <!-- Declare a transaction manager-->
>     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
>                    p:sessionFactory-ref="sessionFactory" />
>  
>     <context:component-scan base-package="com.test.dao"/>
>     <context:annotation-config/>
> </beans>
> load
> (GeoEntity)sessionFactory.getCurrentSession().createQuery("from GeoEntity where id=:id")
>    .setInteger("id", id).uniqueResult();
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users

_______________________________________________
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: Failed to load spatial(Geometry) data MySQL

Sergey21
In reply to this post by Sergey21
Here is my table creation statement, in mysql gui workbeanch it shows data ant it looks like binary

CREATE  TABLE IF NOT EXISTS `test`.`geo` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `geom` GEOMETRY NOT NULL ,
  PRIMARY KEY (`id`) ,
  SPATIAL INDEX `idx_geom` (`geom` ASC) )
ENGINE = MyISAM


Пятница, 7 декабря 2012, 13:54 от Karel Maesen <[hidden email]>:
Hi Sergey,

Could you have a look in the database table and check the contents of the mapped table? What is the table schema? Looks like JDBC is returning a String for the column geom, rather than a Geometry which is normally a varbinary.

Regards,

Karel
On 07 Dec 2012, at 13:37, Sergey wrote:

> I am using MySql, Hibernate 4 and hibernate-spatial-4.0-M1. I tried simply save and load entity, saving was successfull but loading throws exception:
>
> java.lang.ClassCastException: java.lang.String cannot be cast to [B
> at org.hibernate.spatial.dialect.mysql.MySQLGeometryValueExtractor.toJTS(MySQLGeometryValueExtractor.java:47)
> at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
> at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
> at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
> at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
> at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
> at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
> at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2704)
> at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
> at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
> at org.hibernate.loader.Loader.getRow(Loader.java:1373)
> at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
> at org.hibernate.loader.Loader.doQuery(Loader.java:850)
> at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
> at org.hibernate.loader.Loader.doList(Loader.java:2438)
> at org.hibernate.loader.Loader.doList(Loader.java:2424)
> at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
> at org.hibernate.loader.Loader.list(Loader.java:2249)
> at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
> at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
> at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
> at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
> at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
> at com.mm.dao.hibernate.GeoDAO.getById(GeoDAO.java:33)
> at com.mm.service.GeoService.getById(GeoService.java:24)
> at com.mm.service.GeoService$$FastClassByCGLIB$$aeb6c7aa.invoke(<generated>)
> at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
> at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
> at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
> at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
> at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
> at com.mm.service.GeoLocationService$$EnhancerByCGLIB$$f879610f.getById(<generated>)
> at com.mm.controllers.GeoController.updateGeodata(GeoController.java:48)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
> at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
> at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHa
> at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingH
> at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandle
> at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
> at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
> at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
> at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
> at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
> at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
> at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
>
> My entity:
> publicclassGeoEntityimplements java.io.Serializable{
> private Integer id;
> private Point geom;
> //...
> }
>
> entity hbm.xml
> <propertyname="geom"type="org.hibernate.spatial.GeometryType">
> <columnname="geom"sql-type="Geometry"not-null="true"/>
> </property>
> hibernate config:
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:p="http://www.springframework.org/schema/p"
> xmlns:tx="http://www.springframework.org/schema/tx"
> xmlns:context="http://www.springframework.org/schema/context"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
> http://www.springframework.org/schema/tx
> http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
> http://www.springframework.org/schema/context
> http://www.springframework.org/schema/context/spring-context-3.0.xsd
> ">
>
> <context:property-placeholder location="/WEB-INF/classes/jdbc.properties" />
>
> <tx:annotation-driven transaction-manager="transactionManager" />
> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
> <property name="dataSource" ref="dataSource"/>
> <property name="mappingDirectoryLocations" value="classpath:com/test/m/mapping"/>
> <property name="hibernateProperties">
> <props>
> <prop key="hibernate.dialect">org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect</prop>
> <prop key="show_sql">false</prop>
> <prop key="hibernate.order_updates">true</prop>
> <prop key="hibernate.globally_quoted_identifiers">true</prop>
> <prop key="hibernate.hbm2ddl.auto">validate</prop>
> <prop key="hibernate.default_catalog">${app.jdbc.dbname}</prop>
> <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
> </props>
> </property>
> </bean>
>
> <!-- Declare a datasource that has pooling capabilities-->
> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
> destroy-method="close"
> p:driverClass="${app.jdbc.driverClassName}"
> p:jdbcUrl="${app.jdbc.url}"
> p:user="${app.jdbc.username}"
> p:password="${app.jdbc.password}"
> p:acquireIncrement="${dataSource.acquireIncrement}"
> p:idleConnectionTestPeriod="${dataSource.idleConnectionTestPeriod}"
> p:maxPoolSize="${dataSource.maxPoolSize}"
> p:maxStatements="${dataSource.maxStatements}"
> p:minPoolSize="${dataSource.minPoolSize}"
> p:initialPoolSize="${dataSource.initialPoolSize}"/>
>
> <!-- Declare a transaction manager-->
> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
> p:sessionFactory-ref="sessionFactory" />
>
> <context:component-scan base-package="com.test.dao"/>
> <context:annotation-config/>
> </beans>
> load
> (GeoEntity)sessionFactory.getCurrentSession().createQuery("from GeoEntity where id=:id")
> .setInteger("id", id).uniqueResult();
>
> _______________________________________________
> hibernatespatial-users mailing list
> hibernatespatial-users@...
> http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



_______________________________________________
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: Failed to load spatial(Geometry) data MySQL

Karel Maesen
Administrator
Hi Sergey,

We need to figure out why JDBC returns a String rather than a byte-array for the geom property. Could you set the Hibernate property "hibernate.show_sql" to true and check the generated SQL. You can then try to run the SQL statement manually in the MySQL gui workbench.

Would it be possible to run your code in debug-mode, and check the value for the "object" parameter in the class MySQLGeometryValueExtractor.java at line 47?

Regards,

Karel

On 07 Dec 2012, at 18:58, Sergey wrote:

> Here is my table creation statement, in mysql gui workbeanch it shows data ant it looks like binary
>
> CREATE  TABLE IF NOT EXISTS `test`.`geo` (
>   `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
>   `geom` GEOMETRY NOT NULL ,
>   PRIMARY KEY (`id`) ,
>   SPATIAL INDEX `idx_geom` (`geom` ASC) )
> ENGINE = MyISAM
>
>
> Пятница, 7 декабря 2012, 13:54 от Karel Maesen <[hidden email]>:
> Hi Sergey,
>
> Could you have a look in the database table and check the contents of the mapped table? What is the table schema? Looks like JDBC is returning a String for the column geom, rather than a Geometry which is normally a varbinary.
>
> Regards,
>
> Karel
> On 07 Dec 2012, at 13:37, Sergey wrote:
>
> > I am using MySql, Hibernate 4 and hibernate-spatial-4.0-M1. I tried simply save and load entity, saving was successfull but loading throws exception:
> >
> > java.lang.ClassCastException: java.lang.String cannot be cast to [B
> > at org.hibernate.spatial.dialect.mysql.MySQLGeometryValueExtractor.toJTS(MySQLGeometryValueExtractor.java:47)
> > at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
> > at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
> > at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
> > at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2704)
> > at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
> > at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
> > at org.hibernate.loader.Loader.getRow(Loader.java:1373)
> > at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
> > at org.hibernate.loader.Loader.doQuery(Loader.java:850)
> > at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
> > at org.hibernate.loader.Loader.doList(Loader.java:2438)
> > at org.hibernate.loader.Loader.doList(Loader.java:2424)
> > at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
> > at org.hibernate.loader.Loader.list(Loader.java:2249)
> > at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
> > at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
> > at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
> > at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
> > at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
> > at com.mm.dao.hibernate.GeoDAO.getById(GeoDAO.java:33)
> > at com.mm.service.GeoService.getById(GeoService.java:24)
> > at com.mm.service.GeoService$$FastClassByCGLIB$$aeb6c7aa.invoke(<generated>)
> > at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
> > at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
> > at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
> > at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
> > at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> > at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
> > at com.mm.service.GeoLocationService$$EnhancerByCGLIB$$f879610f.getById(<generated>)
> > at com.mm.controllers.GeoController.updateGeodata(GeoController.java:48)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > at java.lang.reflect.Method.invoke(Method.java:601)
> > at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
> > at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
> > at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHa
> > at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingH
> > at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandle
> > at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
> > at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
> > at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
> > at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
> > at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
> > at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> > at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> > at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
> > at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> > at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> > at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
> > at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
> > at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
> > at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> > at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> > at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
> > at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
> > at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> > at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> > at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> > at java.lang.Thread.run(Thread.java:722)
> >
> > My entity:
> > publicclassGeoEntityimplements java.io.Serializable{
> > private Integer id;
> > private Point geom;
> > //...
> > }
> >
> > entity hbm.xml
> > <propertyname="geom"type="org.hibernate.spatial.GeometryType">
> > <columnname="geom"sql-type="Geometry"not-null="true"/>
> > </property>
> > hibernate config:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns:p="http://www.springframework.org/schema/p"
> > xmlns:tx="http://www.springframework.org/schema/tx"
> > xmlns:context="http://www.springframework.org/schema/context"
> > xsi:schemaLocation="
> > http://www.springframework.org/schema/beans 
> > http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
> > http://www.springframework.org/schema/tx 
> > http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
> > http://www.springframework.org/schema/context
> > http://www.springframework.org/schema/context/spring-context-3.0.xsd
> > ">
> >
> > <context:property-placeholder location="/WEB-INF/classes/jdbc.properties" />
> >
> > <tx:annotation-driven transaction-manager="transactionManager" />
> > <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
> > <property name="dataSource" ref="dataSource"/>
> > <property name="mappingDirectoryLocations" value="classpath:com/test/m/mapping"/>
> > <property name="hibernateProperties">
> > <props>
> > <prop key="hibernate.dialect">org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect</prop>
> > <prop key="show_sql">false</prop>
> > <prop key="hibernate.order_updates">true</prop>
> > <prop key="hibernate.globally_quoted_identifiers">true</prop>
> > <prop key="hibernate.hbm2ddl.auto">validate</prop>
> > <prop key="hibernate.default_catalog">${app.jdbc.dbname}</prop>
> > <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
> > </props>
> > </property>
> > </bean>
> >
> > <!-- Declare a datasource that has pooling capabilities-->
> > <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
> > destroy-method="close"
> > p:driverClass="${app.jdbc.driverClassName}"
> > p:jdbcUrl="${app.jdbc.url}"
> > p:user="${app.jdbc.username}"
> > p:password="${app.jdbc.password}"
> > p:acquireIncrement="${dataSource.acquireIncrement}"
> > p:idleConnectionTestPeriod="${dataSource.idleConnectionTestPeriod}"
> > p:maxPoolSize="${dataSource.maxPoolSize}"
> > p:maxStatements="${dataSource.maxStatements}"
> > p:minPoolSize="${dataSource.minPoolSize}"
> > p:initialPoolSize="${dataSource.initialPoolSize}"/>
> >
> > <!-- Declare a transaction manager-->
> > <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
> > p:sessionFactory-ref="sessionFactory" />
> >
> > <context:component-scan base-package="com.test.dao"/>
> > <context:annotation-config/>
> > </beans>
> > load
> > (GeoEntity)sessionFactory.getCurrentSession().createQuery("from GeoEntity where id=:id")
> > .setInteger("id", id).uniqueResult();
> >
> > _______________________________________________
> > hibernatespatial-users mailing list
> > [hidden email]
> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
>

_______________________________________________
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: Failed to load spatial(Geometry) data MySQL

Sergey21
In reply to this post by Sergey21
Hi Karel,

hibernate generates fine sql, it works in workbench:

select geolocatio0_.id as id4_,  geolocatio0_.geom as geom4_, geolocatio0_.dateTimeCreated as dateTime6_4_ from `test`.`geolocation` geolocatio0_ where geolocatio0_.id=?

when i trying simple query in workbench, it returns my value POINT(1 1)
SELECT AsText(geom) FROM geolocation where id=1

after debugging, i didn't found nothing, object value you can see on the image https://www.dropbox.com/s/chgy25hlmnp9ocb/spatial_object.jpg , it seems to be normal (may be should be without double quotes?)


Пятница, 7 декабря 2012, 20:52 от Karel Maesen <[hidden email]>:
Hi Sergey,

We need to figure out why JDBC returns a String rather than a byte-array for the geom property. Could you set the Hibernate property "hibernate.show_sql" to true and check the generated SQL. You can then try to run the SQL statement manually in the MySQL gui workbench.

Would it be possible to run your code in debug-mode, and check the value for the "object" parameter in the class MySQLGeometryValueExtractor.java at line 47?

Regards,

Karel

On 07 Dec 2012, at 18:58, Sergey wrote:

> Here is my table creation statement, in mysql gui workbeanch it shows data ant it looks like binary
>
> CREATE TABLE IF NOT EXISTS `test`.`geo` (
> `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
> `geom` GEOMETRY NOT NULL ,
> PRIMARY KEY (`id`) ,
> SPATIAL INDEX `idx_geom` (`geom` ASC) )
> ENGINE = MyISAM
>
>
> Пятница, 7 декабря 2012, 13:54 от Karel Maesen <karel@...>:
> Hi Sergey,
>
> Could you have a look in the database table and check the contents of the mapped table? What is the table schema? Looks like JDBC is returning a String for the column geom, rather than a Geometry which is normally a varbinary.
>
> Regards,
>
> Karel
> On 07 Dec 2012, at 13:37, Sergey wrote:
>
> > I am using MySql, Hibernate 4 and hibernate-spatial-4.0-M1. I tried simply save and load entity, saving was successfull but loading throws exception:
> >
> > java.lang.ClassCastException: java.lang.String cannot be cast to [B
> > at org.hibernate.spatial.dialect.mysql.MySQLGeometryValueExtractor.toJTS(MySQLGeometryValueExtractor.java:47)
> > at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
> > at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
> > at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
> > at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2704)
> > at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
> > at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
> > at org.hibernate.loader.Loader.getRow(Loader.java:1373)
> > at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
> > at org.hibernate.loader.Loader.doQuery(Loader.java:850)
> > at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
> > at org.hibernate.loader.Loader.doList(Loader.java:2438)
> > at org.hibernate.loader.Loader.doList(Loader.java:2424)
> > at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
> > at org.hibernate.loader.Loader.list(Loader.java:2249)
> > at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
> > at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
> > at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
> > at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
> > at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
> > at com.mm.dao.hibernate.GeoDAO.getById(GeoDAO.java:33)
> > at com.mm.service.GeoService.getById(GeoService.java:24)
> > at com.mm.service.GeoService$$FastClassByCGLIB$$aeb6c7aa.invoke(<generated>)
> > at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
> > at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
> > at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
> > at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
> > at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> > at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
> > at com.mm.service.GeoLocationService$$EnhancerByCGLIB$$f879610f.getById(<generated>)
> > at com.mm.controllers.GeoController.updateGeodata(GeoController.java:48)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > at java.lang.reflect.Method.invoke(Method.java:601)
> > at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
> > at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
> > at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHa
> > at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingH
> > at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandle
> > at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
> > at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
> > at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
> > at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
> > at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
> > at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> > at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> > at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
> > at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> > at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> > at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
> > at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
> > at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
> > at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> > at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> > at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
> > at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
> > at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> > at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> > at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> > at java.lang.Thread.run(Thread.java:722)
> >
> > My entity:
> > publicclassGeoEntityimplements java.io.Serializable{
> > private Integer id;
> > private Point geom;
> > //...
> > }
> >
> > entity hbm.xml
> > <propertyname="geom"type="org.hibernate.spatial.GeometryType">
> > <columnname="geom"sql-type="Geometry"not-null="true"/>
> > </property>
> > hibernate config:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns:p="http://www.springframework.org/schema/p"
> > xmlns:tx="http://www.springframework.org/schema/tx"
> > xmlns:context="http://www.springframework.org/schema/context"
> > xsi:schemaLocation="
> > http://www.springframework.org/schema/beans
> > http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
> > http://www.springframework.org/schema/tx
> > http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
> > http://www.springframework.org/schema/context
> > http://www.springframework.org/schema/context/spring-context-3.0.xsd
> > ">
> >
> > <context:property-placeholder location="/WEB-INF/classes/jdbc.properties" />
> >
> > <tx:annotation-driven transaction-manager="transactionManager" />
> > <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
> > <property name="dataSource" ref="dataSource"/>
> > <property name="mappingDirectoryLocations" value="classpath:com/test/m/mapping"/>
> > <property name="hibernateProperties">
> > <props>
> > <prop key="hibernate.dialect">org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect</prop>
> > <prop key="show_sql">false</prop>
> > <prop key="hibernate.order_updates">true</prop>
> > <prop key="hibernate.globally_quoted_identifiers">true</prop>
> > <prop key="hibernate.hbm2ddl.auto">validate</prop>
> > <prop key="hibernate.default_catalog">${app.jdbc.dbname}</prop>
> > <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
> > </props>
> > </property>
> > </bean>
> >
> > <!-- Declare a datasource that has pooling capabilities-->
> > <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
> > destroy-method="close"
> > p:driverClass="${app.jdbc.driverClassName}"
> > p:jdbcUrl="${app.jdbc.url}"
> > p:user="${app.jdbc.username}"
> > p:password="${app.jdbc.password}"
> > p:acquireIncrement="${dataSource.acquireIncrement}"
> > p:idleConnectionTestPeriod="${dataSource.idleConnectionTestPeriod}"
> > p:maxPoolSize="${dataSource.maxPoolSize}"
> > p:maxStatements="${dataSource.maxStatements}"
> > p:minPoolSize="${dataSource.minPoolSize}"
> > p:initialPoolSize="${dataSource.initialPoolSize}"/>
> >
> > <!-- Declare a transaction manager-->
> > <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
> > p:sessionFactory-ref="sessionFactory" />
> >
> > <context:component-scan base-package="com.test.dao"/>
> > <context:annotation-config/>
> > </beans>
> > load
> > (GeoEntity)sessionFactory.getCurrentSession().createQuery("from GeoEntity where id=:id")
> > .setInteger("id", id).uniqueResult();
> >
> > _______________________________________________
> > hibernatespatial-users mailing list
> > hibernatespatial-users@...
> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
>



_______________________________________________
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: Failed to load spatial(Geometry) data MySQL

Sergey21
In reply to this post by Sergey21
I resolved this, it was problem with old mysql jdbc driver 3.2, updated to 5.xx and everything is ok, thanks


Суббота, 8 декабря 2012, 2:11 от Sergey <[hidden email]>:
Hi Karel,

hibernate generates fine sql, it works in workbench:

select geolocatio0_.id as id4_,  geolocatio0_.geom as geom4_, geolocatio0_.dateTimeCreated as dateTime6_4_ from `test`.`geolocation` geolocatio0_ where geolocatio0_.id=?

when i trying simple query in workbench, it returns my value POINT(1 1)
SELECT AsText(geom) FROM geolocation where id=1

after debugging, i didn't found nothing, object value you can see on the image https://www.dropbox.com/s/chgy25hlmnp9ocb/spatial_object.jpg , it seems to be normal (may be should be without double quotes?)


Пятница, 7 декабря 2012, 20:52 от Karel Maesen <[hidden email]>:
Hi Sergey,

We need to figure out why JDBC returns a String rather than a byte-array for the geom property. Could you set the Hibernate property "hibernate.show_sql" to true and check the generated SQL. You can then try to run the SQL statement manually in the MySQL gui workbench.

Would it be possible to run your code in debug-mode, and check the value for the "object" parameter in the class MySQLGeometryValueExtractor.java at line 47?

Regards,

Karel

On 07 Dec 2012, at 18:58, Sergey wrote:

> Here is my table creation statement, in mysql gui workbeanch it shows data ant it looks like binary
>
> CREATE TABLE IF NOT EXISTS `test`.`geo` (
> `id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
> `geom` GEOMETRY NOT NULL ,
> PRIMARY KEY (`id`) ,
> SPATIAL INDEX `idx_geom` (`geom` ASC) )
> ENGINE = MyISAM
>
>
> Пятница, 7 декабря 2012, 13:54 от Karel Maesen <[hidden email]>:
> Hi Sergey,
>
> Could you have a look in the database table and check the contents of the mapped table? What is the table schema? Looks like JDBC is returning a String for the column geom, rather than a Geometry which is normally a varbinary.
>
> Regards,
>
> Karel
> On 07 Dec 2012, at 13:37, Sergey wrote:
>
> > I am using MySql, Hibernate 4 and hibernate-spatial-4.0-M1. I tried simply save and load entity, saving was successfull but loading throws exception:
> >
> > java.lang.ClassCastException: java.lang.String cannot be cast to [B
> > at org.hibernate.spatial.dialect.mysql.MySQLGeometryValueExtractor.toJTS(MySQLGeometryValueExtractor.java:47)
> > at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
> > at org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
> > at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
> > at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
> > at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2704)
> > at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
> > at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
> > at org.hibernate.loader.Loader.getRow(Loader.java:1373)
> > at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
> > at org.hibernate.loader.Loader.doQuery(Loader.java:850)
> > at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
> > at org.hibernate.loader.Loader.doList(Loader.java:2438)
> > at org.hibernate.loader.Loader.doList(Loader.java:2424)
> > at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
> > at org.hibernate.loader.Loader.list(Loader.java:2249)
> > at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
> > at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
> > at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
> > at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
> > at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
> > at com.mm.dao.hibernate.GeoDAO.getById(GeoDAO.java:33)
> > at com.mm.service.GeoService.getById(GeoService.java:24)
> > at com.mm.service.GeoService$$FastClassByCGLIB$$aeb6c7aa.invoke(<generated>)
> > at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
> > at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
> > at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
> > at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
> > at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> > at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
> > at com.mm.service.GeoLocationService$$EnhancerByCGLIB$$f879610f.getById(<generated>)
> > at com.mm.controllers.GeoController.updateGeodata(GeoController.java:48)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> > at java.lang.reflect.Method.invoke(Method.java:601)
> > at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
> > at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
> > at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHa
> > at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingH
> > at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandle
> > at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
> > at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
> > at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
> > at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
> > at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
> > at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
> > at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
> > at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
> > at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
> > at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
> > at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
> > at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
> > at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
> > at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
> > at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
> > at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
> > at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
> > at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> > at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> > at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> > at java.lang.Thread.run(Thread.java:722)
> >
> > My entity:
> > publicclassGeoEntityimplements java.io.Serializable{
> > private Integer id;
> > private Point geom;
> > //...
> > }
> >
> > entity hbm.xml
> > <propertyname="geom"type="org.hibernate.spatial.GeometryType">
> > <columnname="geom"sql-type="Geometry"not-null="true"/>
> > </property>
> > hibernate config:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <beans xmlns="http://www.springframework.org/schema/beans"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns:p="http://www.springframework.org/schema/p"
> > xmlns:tx="http://www.springframework.org/schema/tx"
> > xmlns:context="http://www.springframework.org/schema/context"
> > xsi:schemaLocation="
> > http://www.springframework.org/schema/beans
> > http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
> > http://www.springframework.org/schema/tx
> > http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
> > http://www.springframework.org/schema/context
> > http://www.springframework.org/schema/context/spring-context-3.0.xsd
> > ">
> >
> > <context:property-placeholder location="/WEB-INF/classes/jdbc.properties" />
> >
> > <tx:annotation-driven transaction-manager="transactionManager" />
> > <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
> > <property name="dataSource" ref="dataSource"/>
> > <property name="mappingDirectoryLocations" value="classpath:com/test/m/mapping"/>
> > <property name="hibernateProperties">
> > <props>
> > <prop key="hibernate.dialect">org.hibernate.spatial.dialect.mysql.MySQLSpatialDialect</prop>
> > <prop key="show_sql">false</prop>
> > <prop key="hibernate.order_updates">true</prop>
> > <prop key="hibernate.globally_quoted_identifiers">true</prop>
> > <prop key="hibernate.hbm2ddl.auto">validate</prop>
> > <prop key="hibernate.default_catalog">${app.jdbc.dbname}</prop>
> > <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
> > </props>
> > </property>
> > </bean>
> >
> > <!-- Declare a datasource that has pooling capabilities-->
> > <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
> > destroy-method="close"
> > p:driverClass="${app.jdbc.driverClassName}"
> > p:jdbcUrl="${app.jdbc.url}"
> > p:user="${app.jdbc.username}"
> > p:password="${app.jdbc.password}"
> > p:acquireIncrement="${dataSource.acquireIncrement}"
> > p:idleConnectionTestPeriod="${dataSource.idleConnectionTestPeriod}"
> > p:maxPoolSize="${dataSource.maxPoolSize}"
> > p:maxStatements="${dataSource.maxStatements}"
> > p:minPoolSize="${dataSource.minPoolSize}"
> > p:initialPoolSize="${dataSource.initialPoolSize}"/>
> >
> > <!-- Declare a transaction manager-->
> > <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
> > p:sessionFactory-ref="sessionFactory" />
> >
> > <context:component-scan base-package="com.test.dao"/>
> > <context:annotation-config/>
> > </beans>
> > load
> > (GeoEntity)sessionFactory.getCurrentSession().createQuery("from GeoEntity where id=:id")
> > .setInteger("id", id).uniqueResult();
> >
> > _______________________________________________
> > hibernatespatial-users mailing list
> > [hidden email]
> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
>
>


_______________________________________________
hibernatespatial-users mailing list
hibernatespatial-users@...
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users



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