Reputation: 421
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?
Upvotes: 6
Views: 29320
Reputation: 686
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);
Upvotes: 0
Reputation: 506
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
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!
Upvotes: 0
Reputation: 421
Thanks for your replies,
I solved using a namedQuery retrieving a whole object with all fields, with his type geometry.
Many thanks
Upvotes: 0
Reputation: 570325
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;
Upvotes: 5
Reputation: 72860
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.
Upvotes: 3