org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002
Asked Answered
Y

5

6

I'm getting org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002 when I try to do a JPA nativeQuery to get a geometry field type.

I'm using Oracle and org.hibernatespatial.oracle.OracleSpatial10gDialect.

The geometry field 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>
</bean>

How can this be solved? Or how to force the type of the geometry to get this working?

Yongyoni answered 15/6, 2010 at 10:14 Comment(0)
H
5

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;
Hamamelidaceous answered 15/6, 2010 at 16:38 Comment(0)
V
3

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.

Varro answered 15/6, 2010 at 10:18 Comment(1)
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();Yongyoni
Y
0

Thanks for your replies,

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

Many thanks

Yongyoni answered 18/6, 2010 at 9:51 Comment(0)
K
0

Got the same error message when using full-text search and here's what helped me:

installing the following extension in PgAdmin: unaccent; (for Postgres users - there is an example on the bottom)

Type: CREATE EXTENSION unaccent; and the extension is created/installed and is now available to the users of that database.

BE aware, this should be installed on the server, where your application lives, too.

And what are the next steps:

  • creating custom dialect (so that the syntax would be recognised and read)
  • add that custom dialect in your application.properties file.

Here comes the example:

I am using Spring Boot 2.0 and Postgres as a DB:

After installing the extension, we create the following classes: PgFullTextFunction and PostgreSQL82Dialect described in the article: http://www.welinux.cl/wordpress/implementing-postgresql-full-text-with-jpa-entities/

You could try this one, too: https://www.zymr.com/postgresql-full-text-searchfts-hibernate/

But I am using the first example for the classes and it is working, I just removed the following line: value = org.apache.commons.lang3.StringUtils.stripAccents(value); from the PgFullTextFunction class.

In general, as I understand it, we create a class that implements the SQL function interface and that way we create a new dialect. The fts(), registered in the class PgFullTextDialect is like a wrapper for the render method in our PgFullTextFunction class.

After that in our application.properties file/files we add the path to our newly created Dialect:

spring.jpa.properties.hibernate.dialect=com.your.package.name.persistence.PgFullTextDialect

If you want to use a specific configuration for your full-text functions, you can check out the second link I posted from zymr.com above, the example there is with additional language configuration.

I hope this could help!

Katt answered 17/10, 2019 at 4:42 Comment(0)
S
0

Your query:

Query query = entityManager.createNativeQuery("Query String");

You forgot to add the entity class parameter.

You should add the entity class parameter.

For Example:

Query query = entityManager.createNativeQuery("Query String", EntityName.class);
Spinoff answered 7/5, 2020 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.