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

这一生的挚爱 提交于 2019-12-07 05:27:14

问题


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?


回答1:


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;



回答2:


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.




回答3:


Thanks for your replies,

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

Many thanks




回答4:


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!



来源:https://stackoverflow.com/questions/3044244/org-hibernate-mappingexception-no-dialect-mapping-for-jdbc-type-2002

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!