org.hibernate.MappingException:没有 JDBC 类型的方言映射:2002
当我尝试执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以尝试使用以下映射定义:
而不是:
Could you try with the following mapping definition:
Instead of:
问题不在于您的查询或映射,而在于您的 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.
感谢您的回复,
我解决了使用命名查询检索具有所有字段的整个对象及其类型几何的问题。
非常感谢
Thanks for your replies,
I solved using a namedQuery retrieving a whole object with all fields, with his type geometry.
Many thanks
使用全文搜索时收到相同的错误消息,这对我有帮助:
在 PgAdmin 中安装以下扩展:unaccent; (对于 Postgres 用户 - 底部有一个示例)
类型:
CREATE EXTENSION unaccent;
并且扩展已创建/安装,现在可供该数据库的用户使用。请注意,这应该安装在您的应用程序所在的服务器上。
下一步是什么:
下面是示例:
我使用 Spring Boot 2.0 和 Postgres 作为数据库:
安装扩展后,我们创建以下类:文章中描述的
PgFullTextFunction
和PostgreSQL82Dialect
: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 的路径:如果您想为全文功能使用特定配置,您可以查看我的第二个链接上面发布自 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:
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
andPostgreSQL82Dialect
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 classPgFullTextDialect
is like a wrapper for the render method in ourPgFullTextFunction
class.After that in our
application.properties
file/files we add the path to our newly created Dialect: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!
您的查询:
您忘记添加实体类参数。
您应该添加实体类参数。
例如:
Your query:
You forgot to add the entity class parameter.
You should add the entity class parameter.
For Example: