1

Let's consider a simple Postgres database with only one table and one column, that is of type DATE, i.e.:

CREATE DATABASE test;
CREATE TABLE test_table
(
    date_test DATE NOT NULL DEFAULT CURRENT_DATE
);

From the Hibernate documentation regarding basic types and PostgresSQL documentation regarding using Java 8 Date and Time classes, I can clearly see that I should be able to map that table like this:

@Entity
@Table(name = "test_table")
public class TestTable
{
    @Column(name = "date_test")
    private LocalDate dateTest;
}

quite easily, without a need to write @Temporal or any stuff alike. From the Hibernate documentation I can read:

Because the mapping between Java 8 Date/Time classes and the SQL types is implicit, there is not need to specify the @Temporal annotation. Setting it on the java.time classes throws the following exception: org.hibernate.AnnotationException: @Temporal should only be set on a java.util.Date or java.util.Calendar property

However, I'm getting an error

Schema-validation: wrong column type encountered in column [date_test] in table [test_table]; found [date (Types#DATE)], but expecting [bytea (Types#VARBINARY)]

In my pom.xml file I've got:

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.4-1206-jdbc42</version>
</dependency>

and since I'm also using Spring Boot, in application.properties I've got

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect

Am I wrong about documentation? Should I write a Converter or is there any other way?

EDIT
Currently my pom.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>Invoices-desktop</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <!-- copy fxml and css resources -->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.css</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/CurrencyDemo/java</directory>
                <includes>
                    <include>**/*.fxml</include>
                    <include>**/*.css</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </resource>
        </resources>

    </build>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>com.Main</start-class>
        <java.version>1.8</java.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
    </parent>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>1.5.6.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>org.hibernate</artifactId>
                    <groupId>hibernate-core</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1206-jdbc42</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.4.1.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.10.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-CurrencyDemo</artifactId>
            <scope>CurrencyDemo</scope>
        </dependency>

        <dependency>
            <groupId>com.ibm.icu</groupId>
            <artifactId>icu4j</artifactId>
            <version>59.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.7</version>
        </dependency>

    </dependencies>

</project>

and now I'm getting:

java.lang.NoSuchMethodError:org.hibernate.engine.spi.Session‌​FactoryImplementor.g‌​etProperties()Ljava/‌​util/Properties;

2 Answers 2

1

You should use newer version of Hibernate.

I can not say which version start support Java 8 Dates, but in my project I use hibernate-core:5.2.6.Final.

I faced with similar problem when use a spring-boot-starter-data-jpa:1.5.6.RELEASE, that depends on hibernate-core:5.0.12.Final.

NOTE: If you used the spring-boot-starter-data-jpa, you should exclude hibernate-core from dependencies.

Sign up to request clarification or add additional context in comments.

Comments

1

Thanks to Ruslan K.'s suggestion and this answer https://stackoverflow.com/a/44455146/4671908 I was able to modify my pom.xml properly. Unfortunately spring-boot-starter-data-jpa 1.5.6.RELEASE alone does not support latest Hibernate modifications, so I excluded both hibernate-core and hibernate-entitymanager from pom.xml, which looks like this right now

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>1.5.6.RELEASE</version>
            <exclusions>
                <exclusion>
                    <artifactId>org.hibernate</artifactId>
                    <groupId>hibernate-core</groupId>
                </exclusion>

                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-entitymanager</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.10.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.2.10.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.