views:

64

answers:

3

Hi at all,

I'm having a issue trying to get working a JPA nativeQuery. I'm having a org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002 when a try to do a nativeQuery and get a geometry field type. I use oracle and org.hibernatespatial.oracle.OracleSpatial10gDialect.

The geom fields is mapped as:

  @Column(name="geometry")  
  @Type(type = "org.hibernatespatial.GeometryUserType")  
  private Geometry geometry;



List<Object> listFeatures= new LinkedList<Object>();



 Query query= entityManager.createNativeQuery(
    "SELECT "+ slots +" , geometry FROM  edtem_features feature, edtem_dades dada WHERE" +
    " feature."+ tematic.getIdGeomField() +" = dada."+ tematic.getIdDataField()+ 
    " AND dada.capesid= "+ tematic.getCapa().getId() +
    " AND feature.geometriesid= "+ tematic.getGeometria().getId());
  listFeatures.addAll( query.getResultList());

This is my hibernate configuration over spring+struts2

<bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />

        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="databasePlatform" value="org.hibernatespatial.oracle.OracleSpatial10gDialect" />
                <property name="showSql" value="true" />
            </bean>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernatespatial.oracle.OracleSpatial10gDialect</prop>
                <prop key="hibernate.default_schema">my_schema</prop>
            </props>
        </property>
    </b

ean>

Anybody knows a solution? or how to force the type of the geometry to get wroking this...

MANY Thanks in advance. Moli

+2  A: 

The problem is not in your query or your mapping, but in your Hibernate configuration. You will find that you are specifying the wrong string for the name of the SQL dialect to use. Suggest you post the Hibernate configuration file you are using.

David M
Thanks for your time, I've edited my post to show my jpa configuration. My project is working well when I use Hql queries like:Geometries result = null;result = (Geometries) entityManager.createQuery( "SELECT geo FROM Geometries geo WHERE geo.id = ?1") .setParameter(1, id ).getSingleResult();
Moli
A: 

Could you try with the following mapping definition:

@Column(name = "geometry", columnDefinition="Geometry", nullable = true) 
private Geometry geometry;

Instead of:

@Column(name="geometry")  
@Type(type = "org.hibernatespatial.GeometryUserType")  
private Geometry geometry;
Pascal Thivent
A: 

Thanks for your replies,

I solved using a namedQuery retrieving a whole object with all fields, with his type geometry.

Many thanks

Moli