简体   繁体   中英

Hibernate Dialect?

My PostgreSQL version is 10.5 . What is the correct Hibernate Dialect for hibernate.version 4.3.8.Final ?

Please note that the question is about the right Hibernate Dialect; Hibernate versions may be old.

Hibernate org.hibernate.dialect.PostgreSQL95Dialect or org.hibernate.dialect.PostgreSQL82Dialect ?

Here's application.properties

#Database related properties
database.driver=com.postgresql.jdbc.Driver
database.url=jdbc:postgresql://localhost:5432/springdb
database.user=postgres
database.password=*****************

#Hibernate related properties
hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=update

Here's pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.package.spring</groupId>
    <artifactId>SpringMVCHibernateCRUD</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>SpringMVCHibernateCRUD Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <!-- Specifying the Versions of Spring, Hiberante, PostgreSQL etc -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>4.1.5.RELEASE</spring.version>
        <hibernate.version>4.3.8.Final</hibernate.version>  
        <postgresql.version>9.4.1212.jre6</postgresql.version>
        <junit-version>4.12</junit-version>
        <servlet-api-version>3.1.0</servlet-api-version>
        <jsp-version>2.1</jsp-version>
        <jstl-version>1.2</jstl-version>
        <java.version>1.10</java.version>       
    </properties>
       <dependencies>
              <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Hibernate 4 dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!--PostgreSQL Connector -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgresql.version}</version>
        </dependency>

        <!-- Servlet and JSP -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet-api-version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>${jsp-version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- JSTL dependency -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl-version}</version>
        </dependency>

        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit-version}</version>
            <scope>test</scope>
        </dependency>

       </dependencies>
       <build>
              <finalName>SpringMVCHibernateCRUD</finalName>
              <plugins>
              <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>

       </build>
</project>

Because postgresql 10 is new. I think org.hibernate.dialect.PostgreSQL95Dialect is the way to go. I did not see any newer class here.

All dialects

While searching I saw https://www.muehlencord.de/wordpress/2018/01/30/hibernate-uuid-issues-postgres-10/ . Extra info: try to stick with version 9 until all 10 issues sorted out.

An ideal SQL dialect for Postgres 8.2 and later is org.hibernate.dialect.PostgreSQL82Dialect while for PostgreSQL version 9.5 and later is org.hibernate.dialect.PostgreSQL95Dialect. As your version is 10.5. The best choice for you is to use PostgreSQL95Dialect until more updated dialect comes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM