You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doc: hibernate.dialect_resolvers vs HibernateJpaVendorAdapter.setDatabase [SPR-16428] #20974
Hibernate property hibernate.dialect_resolvers let specify custom Dialect resolvers if no hibernate.dialect is set. I cannot get the property to work with Spring Data JPA and debugging I've found what I guess is the issue, i.e. HibernateJpaVendorAdapter at Line 130 always sets the dialect property and doing so Hibernate will not take into account the dialect_resolvers property.
What’s the purpose of the else branch at all? If the dialect isn’t set by the user, Hibernate’s already has its own default resolver that will select the right one, even more precisely than this (which just returns the latest dialect class, without checking the database version).
So you are setting the "database" property on HibernateJpaVendorAdapter but do not want the dialect to be directly derived from it? Could you simply drop that property since that's pretty much its sole purpose in HibernateJpaVendorAdapter? In case of Database.DEFAULT, no Hibernate property is going to be set since determineDatabaseDialectClass will return null, which in turn means that Hibernate's standard dialect resolution mechanism kicks in.
I'm not setting any other property than hibernate.dialect_resolvers, I'm not referencing HibernateJpaVendorAdapter anywhere. This is my application.yml:
The workaround I'm using now is to specify also hibernate.dialect: # empty so that the property set by Spring will be overwritten with an empty string and Hibernate will ignore that, triggering the resolvers. It works but it's very counter-intuitive and I needed a lot of debugging to figure it out.
From a Spring Framework perspective, this is essentially a documentation issue for anybody configuring HibernateJpaVendorAdapter directly. Let's repurpose this ticket for an explicit note about HibernateJpaVendorAdapter.setDatabase vs hibernate.dialect_resolvers, clarifying that they are mutually exclusive.
Activity
spring-projects-issues commentedon Jan 27, 2018
Giovanni Lovato commented
What’s the purpose of the
elsebranch at all? If the dialect isn’t set by the user, Hibernate’s already has its own default resolver that will select the right one, even more precisely than this (which just returns the latest dialect class, without checking the database version).spring-projects-issues commentedon Jan 29, 2018
Juergen Hoeller commented
So you are setting the "database" property on
HibernateJpaVendorAdapterbut do not want the dialect to be directly derived from it? Could you simply drop that property since that's pretty much its sole purpose inHibernateJpaVendorAdapter? In case ofDatabase.DEFAULT, no Hibernate property is going to be set sincedetermineDatabaseDialectClasswill returnnull, which in turn means that Hibernate's standard dialect resolution mechanism kicks in.spring-projects-issues commentedon Jan 29, 2018
Giovanni Lovato commented
I'm not setting any other property than
hibernate.dialect_resolvers, I'm not referencingHibernateJpaVendorAdapteranywhere. This is myapplication.yml:The workaround I'm using now is to specify also
hibernate.dialect: # emptyso that the property set by Spring will be overwritten with an empty string and Hibernate will ignore that, triggering the resolvers. It works but it's very counter-intuitive and I needed a lot of debugging to figure it out.spring-projects-issues commentedon Jan 29, 2018
Juergen Hoeller commented
It turns out that Spring Boot is setting the database by default: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties. It looks like you could also set
spring.jpa.databasetodefaultfor Hibernate's default algorithm, next to your customhibernate.dialect_resolversconfiguration, avoiding the awkward need to sethibernate.dialectto empty.From a Spring Framework perspective, this is essentially a documentation issue for anybody configuring
HibernateJpaVendorAdapterdirectly. Let's repurpose this ticket for an explicit note aboutHibernateJpaVendorAdapter.setDatabasevshibernate.dialect_resolvers, clarifying that they are mutually exclusive.spring-projects-issues commentedon Jan 29, 2018
Giovanni Lovato commented
That's okay for me. Thank you for the explanation!
spring-projects-issues commentedon Jan 29, 2018
Juergen Hoeller commented
I've added corresponding notes to the
AbstractJpaVendorAdapter.setDatabaseand the generalHibernateJpaVendorAdapterjavadocs.