Skip to content
Advertisement

How to use custom data base dialect in spring data?

I need to avoid some bug in db2 dialect in hibernate. I use spring data + gradle (several modules) + kotlin I created my custom dialect

DB2zOSDialect : DB2Dialect() 

And try to add it to application.properties

spring:
  jpa:
    properties:
      hibernate:
        dialect: com.my.config.DB2zOSDialect 

But spring data continuous using DB2Dialect

I tried the same code but using java + maven + the same spring data and it’s works.

So, i have no ideas why my custom dialect isn’t being use by spring data.

Are there ways how to add dialect to spring data?

Advertisement

Answer

So, i solved problem by my own, but i still don’t know why behavior is different.

I set

spring.jpa.database = default

and added

spring.jpa.properties.hibernate.dialect_resolvers = com.my.config.CustomDialectResolver

And wrote simple resolver

class CustomDialectResolver : DialectResolver {

    override fun resolveDialect(info: DialectResolutionInfo?): Dialect {
        return DB2zOSDialect()
    }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement