Skip to content

Doc: hibernate.dialect_resolvers vs HibernateJpaVendorAdapter.setDatabase [SPR-16428] #20974

Closed

Description

@spring-projects-issues

Giovanni Lovato opened SPR-16428 and commented

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.

if (getDatabasePlatform() != null) {
    jpaProperties.put(AvailableSettings.DIALECT, getDatabasePlatform());
}
else {
    Class<?> databaseDialectClass = determineDatabaseDialectClass(getDatabase());
    if (databaseDialectClass != null) {
        jpaProperties.put(AvailableSettings.DIALECT, databaseDialectClass.getName());
    }
}

Affects: 4.3.14, 5.0.3

Issue Links:

Referenced from: commits e1fa65a, f187ca6

Backported to: 4.3.15

Activity

  1. spring-projects-issues commented on Jan 27, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Giovanni Lovato commented

    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).

  2. spring-projects-issues commented on Jan 29, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    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.

  3. spring-projects-issues commented on Jan 29, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Giovanni Lovato commented

    I'm not setting any other property than hibernate.dialect_resolvers, I'm not referencing HibernateJpaVendorAdapter anywhere. This is my application.yml:

    spring:
      datasource:
        jndi-name: java:/datasources/docker/postgres/default
      jpa:
        open-in-view: false
        show-sql: true
        generate-ddl: true
        properties:
          hibernate:
            dialect_resolvers: it.axians.oss.data.jpa.dialect.ExtendedDialectResolver

    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.

  4. spring-projects-issues commented on Jan 29, 2018

    @spring-projects-issues
    CollaboratorAuthor

    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.database to default for Hibernate's default algorithm, next to your custom hibernate.dialect_resolvers configuration, avoiding the awkward need to set hibernate.dialect to empty.

    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.

  5. spring-projects-issues commented on Jan 29, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Giovanni Lovato commented

    That's okay for me. Thank you for the explanation!

  6. spring-projects-issues commented on Jan 29, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've added corresponding notes to the AbstractJpaVendorAdapter.setDatabase and the general HibernateJpaVendorAdapter javadocs.

  7. added
    in: data
    status: backported
    type: task
    on Jan 11, 2019
  8. added this to the 5.0.4 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datastatus: backportedtype: task

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions