oracle org.hibernate.MappingException:没有 JDBC 类型的方言映射:2002

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3044244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:49:48  来源:igfitidea点击:

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

javaoraclehibernatespatial

提问by Moli

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

我收到org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002的时候我尝试做一个JPA nativeQuery获得几何字段类型。

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

我正在使用 Oracle 和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

这是我在 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?

如何解决这个问题?或者如何强制几何类型来使其工作?

回答by Pascal Thivent

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;

回答by David M

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.

问题不在于您的查询或映射,而在于您的 Hibernate 配置。您会发现为要使用的 SQL 方言的名称指定了错误的字符串。建议您发布您正在使用的 Hibernate 配置文件。

回答by Moli

Thanks for your replies,

感谢您的回复,

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

我解决了使用 namedQuery 检索具有所有字段的整个对象以及他的类型几何的问题。

Many thanks

非常感谢

回答by Reneta

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)

在 PgAdmin 中安装以下扩展:unaccent;(对于 Postgres 用户 - 底部有一个示例)

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

类型:CREATE EXTENSION unaccent;并且扩展被创建/安装并且现在可供该数据库的用户使用。

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.
  • 创建自定义方言(以便识别和读取语法)
  • 在 application.properties 文件中添加该自定义方言。

Here comes the example:

下面是例子:

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

我使用 Spring Boot 2.0 和 Postgres 作为数据库:

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

安装扩展后,我们创建以下类:PgFullTextFunctionPostgreSQL82Dialect在文章中描述: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/

你也可以试试这个: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 PgFullTextFunctionclass.

但是我使用的类的第一个例子,它是工作,我只是删除以下行: value = org.apache.commons.lang3.StringUtils.stripAccents(value); 从PgFullTextFunction班级。

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 PgFullTextDialectis like a wrapper for the render method in our PgFullTextFunctionclass.

一般来说,据我所知,我们创建了一个实现 SQL 函数接口的类,这样我们就创建了一种新的方言。的fts(),在类注册PgFullTextDialect是像我们的渲染方法的包装PgFullTextFunction类。

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

之后,在我们的application.properties文件/文件中,我们将路径添加到我们新创建的方言中:

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.

如果您想为全文功能使用特定的配置,您可以查看我从上面 zymr.com 发布的第二个链接,该示例包含附加语言配置。

I hope this could help!

我希望这会有所帮助!

回答by Oguzhan Cevik

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);