Hi,
I have been working with a Kotlin/SpringBoot application and I have ran across the following error:
"No Dialect mapping for
JDBC type"
In simple terms, my app includes the following:
- Entity class where one of the field is of JSON type (more details to follow)
- Model entity
- an Interface called Event whose implementation is then in two classes (signifying different event types/tokens). This is where I think the issue is as I am trying to map a field to an interface, but more to follow in terms of details.
I have consulted a variety of sources with different approaches:
https://vladmihalcea.com/hibernate-no-dialect-mapping-for-jdbc-type/
https://stackoverflow.com/questions/15974474/mapping-postgresql-json-column-to-hibernate-value-type
https://stackoverflow.com/questions/21630370/no-dialect-mapping-for-jdbc-type-2003
https://stackoverflow.com/questions/59967180/how-to-create-custom-jsonb-mapper-for-postgresql-and-hibernate-in-kotlin
I have ended up creating a custom jsonb mapper along these lines:
https://stackoverflow.com/questions/59967180/how-to-create-custom-jsonb-mapper-for-postgresql-and-hibernate-in-kotlin
https://github.com/thjanssen/HibernateJSONBSupport/tree/master/PostgresJSONB/src/main/java/org/thoughts/on/java/model
In a nutshell, the solution involves:
- Register custom PostgreSQL95Dialect which has jsonb type
- Implement Hibernate's UserTypeinterface with custom mapping
- Annotate Entity with @TypeDef of custom implementation
Here is my actual implementation:
Entity
The implementation of the Event interface looks like this:
MyJsonCustomType is my custom implementation of Hibernate's UserType interface with custom mapping. I am not posting all, but just an excerpt:
My Event interface is as follow:
While the Dto/model looks like this:
And here is the custom PostgreSQL95Dialect implementation:
I am not getting "No Dialect mapping for JDBC type" anylonger, however I am not getting the following:
"Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: property mapping has wrong number of columns:"
Can you help? Where am I going wrong? is the issue down to the fact that I am passing in the entity and dto the interface itself and not the concrete class?