Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Dealing with "No Dialect mapping for JDBC type" while working with JSON properties

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?




 
Rancher
Posts: 4553
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the full exception?
That will give the details of the issue...it should have the class name and the field it's having issues with.
 
Geane Norm
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you post the full exception?
That will give the details of the issue...it should have the class name and the field it's having issues with.



Dave Tolls wrote:Can you post the full exception?
That will give the details of the issue...it should have the class name and the field it's having issues with.



Hi,
thank you for your reply. In the meantime, I have changed my approach and went for this:

https://vladmihalcea.com/how-to-map-json-collections-using-jpa-and-hibernate/

after a conversation here: https://stackoverflow.com/questions/59967180/how-to-create-custom-jsonb-mapper-for-postgresql-and-hibernate-in-kotlin

in a nutshell, I have removed the custom type implementation.

Here is my implementation:

Entity



Model



Custom dialect extension



please note that the same error is shown when passing simply "jsnob" instead of JsonNodeBinaryType::class.javaObjectType.name.

That custom class is then referenced in the application.yml:



Here is the full stacktrace:

2020-04-21 14:09:13.793 ERROR 41235 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed



I seem to have followed all the steps and still I am getting the same No Dialect issue. Am i missing anything?

Thank you
 
Geane Norm
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still struggling with the issue and I do not seem to have found a solution.

I have modified my custom Dialect implementation:



but I am still getting the very same error. From https://vladmihalcea.com/hibernate-no-dialect-mapping-for-jdbc-type/, it is given multiple options to address the issue and I went for "Mapping the JDBC Types.OTHER to JsonNodeBinaryType at the Dialect level", but shall I also modify my repository? And if so, how? Shall I also do it at the NativeQuery level?

Thank you
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic