Spring 运行的时候提示数据库方言错误

aused by: java.lang.ClassNotFoundException: org.hibernate.dialect.PostgreSQL82Dialect

问题和解决

上面的问题不是因为数据库配置的问题导致的。

而是在 pom 文件中。

        <!-- hibernate enhancement   -->
        <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-55</artifactId>
            <version>2.21.1</version>
        </dependency>

在 Spring 3 的版本中,Hibernate 已经开始使用 6 的版本。

hibernate-types-55 这个会导致数据类型的问题。

所以应该使用:

        <!-- hibernate enhancement   -->
        <dependency>
            <groupId>com.vladmihalcea</groupId>
            <artifactId>hibernate-types-60</artifactId>
            <version>2.21.1</version>
        </dependency>

这个版本才可以。

Yes, this is a classic case of Spring and Hibernate not working together, not a Postgres problem. Hibernate 6 is now used by Spring Boot 3, and PostgreSQL82Dialect is no longer there. When you pull in hibernate-types-55, it brings Hibernate 5 assumptions into a Hibernate 6 runtime. This causes a ClassNotFoundException.

The right fix is to switch to hibernate-types-60. If you’re having this problem, also check spring.jpa.database-platform. With modern Spring Boot and PostgreSQL, you usually don’t even need to set a dialect. Hibernate will find it on its own.

In short, all extensions must work with Spring Boot 3 and Hibernate 6. combining There will always be bad things that happen with 5.x artifacts.

2 Likes