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

发布于 2024-09-05 17:09:20 字数 1767 浏览 2 评论 0原文

当我尝试执行 JPA nativeQuery 来获取几何字段类型时,我收到 org.hibernate.MappingException: No Dialect mapping for JDBC type: 2002

我正在使用 Oracle 和 org.hibernatespatial.oracle.OracleSpatial10gDialect 。

几何字段映射为:

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

倒带 2024-09-12 17:09:20

您可以尝试使用以下映射定义:

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

而不是:

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

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;
最后的乘客 2024-09-12 17:09:20

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

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.

云胡 2024-09-12 17:09:20

感谢您的回复,

我解决了使用命名查询检索具有所有字段的整个对象及其类型几何的问题。

非常感谢

Thanks for your replies,

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

Many thanks

〆凄凉。 2024-09-12 17:09:20

使用全文搜索时收到相同的错误消息,这对我有帮助:

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

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

请注意,这应该安装在您的应用程序所在的服务器上。

下一步是什么:

  • 创建自定义方言(以便识别和读取语法)
  • 将该自定义方言添加到您的 application.properties 文件中。

下面是示例:

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

安装扩展后,我们创建以下类:文章中描述的 PgFullTextFunctionPostgreSQL82Dialect
http://www.welinux.cl/wordpress /implementing-postgresql-full-text-with-jpa-entities/

你也可以尝试这个:
https://www.zymr.com/postgresql-full-text-searchfts -hibernate/

但我正在使用类的第一个示例并且它正在工作,我刚刚删除了
以下行:
value = org.apache.commons.lang3.StringUtils.stripAccents(value);
来自 PgFullTextFunction 类。

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

之后,在我们的 application.properties 文件中,我们添加新创建的 Dialect 的路径:

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

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

我希望这能有所帮助!

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!

雨轻弹 2024-09-12 17:09:20

您的查询:

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

您忘记添加实体类参数。

您应该添加实体类参数。

例如:

Query query = entityManager.createNativeQuery("Query String", EntityName.class);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文