1

I am using Java 8 along with Spring-Boot 1.5.10.RELEASE.

I still seem to need @EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class }) in my Application class.

I thought Spring-Boot supports Jsr310/Java8 LocalDate API starting 1.4 (according to https://github.com/spring-projects/spring-boot/issues/2721)? I am asking this, because in the 4th reply on that issue mentioned above it is mentioned, that using @EntityScan switches off the default behavior. I think

I should not need this - or do I?

Here are the relevant parts of my pom.xml:

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-oauth2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <!-- <scope>runtime</scope> -->
    </dependency>

    <!-- some other libraries, that do not contain anything hibernate/JPA -->

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>

    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.9.0</version>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.10.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.10.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Edgware.SR3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

In my effective POM I do have both hazelcast-hibernate4 and hazelcast-hibernate5. Is this correct? Or is something wrong with my pom.xml?

Related SO-Q&A: New Spring Data JDK8 Jsr310JpaConverters not working automatically?

Note: this question is not related to the jackson-part (JSON) of the JSR310 problem as I did solve it by properly declaring com.fasterxml.jackson.datatype:jackson-datatype-jsr310 as a dependency.

Update: According to mvn depedency:tree I only use hibernate-core 5.0.12.Final, hibernate-entitymanager 5.0.12.Final and hibernate-validator 5.3.6.Final. All of them are parts of some spring-boot packages.

This leaves me puzzled: if JSR310Convverters for LocalDate were implemented in hibernate 5 - why do I still have to use @EntityScan-annotation?

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Igor
  • 1,582
  • 6
  • 19
  • 49
  • The support was not added directly in spring since it was being fixed hibernate 5 https://hibernate.atlassian.net/browse/HHH-8844. You would need hibernate-java8 dependency to address any issues. And I would suggest you read the comments from philwebb commented on Apr 5, 2016 and holgerstolzenberg commented on Nov 6, 2015 https://github.com/spring-projects/spring-boot/issues/2763 which will help you get more clarity. Btw, why do you need both hazelcast versions? hazelcast-hibernate5 should alone be enough. – Vikram Palakurthi Mar 31 '18 at 03:06
  • @VikramPalakurthi: I will have to dig up the dependency-tree to see where they are coming from. The effective POM view says that both versions have been added (I did **not** intend this as I am writing a simple service with database access, currently using H2DB (without pooling)). – Igor Mar 31 '18 at 05:39
  • Okay: it seems the effective POM is showing too many dependencies... according to *"mvn depedency:tree* I **only** use **hibernate-core 5.0.12.Final**, **hibernate-entitymanager 5.0.12.Final** and **hibernate-validator 5.3.6.Final**. All of them are parts of some spring-boot packages. No version 4 AND 5... I will go read the issue you suggested. Thanks so far. – Igor Mar 31 '18 at 05:50
  • Any update on this one? I still have to use `@EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class})` as well – Patrik Mihalčin Apr 26 '18 at 17:05
  • @PatrikMihalčin I am going to post a reply that currently works for me. – Igor Apr 27 '18 at 12:52

2 Answers2

1

You have to add dependency:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
</dependency>

and you won't need to specify @EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class}) on your Application class anymore

Patrik Mihalčin
  • 3,341
  • 7
  • 33
  • 68
0

I found an "okay"-solution for myself. There are 2 aspects to cover in this context:

  • JSON-conversion
  • JPA-conversion

For JSON-conversion I set this property in the application.properties file:

spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false

In order to have the database (I am using H2) contain TIMESTAMP-type columns with values rather than VARBINARY-type columns with values one cannot read right away nor properly sort, one currently seems to have to include:

@EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class })

I wish it would automatically use those converters since I am on Java 8 anyway, but unfortunately it does not seem to do that.

Please note the following:

This isn't quite as straightforward as I thought. Using @EntityScan on one of our configuration classes has the unwanted side-effect of switching off the default which is retrieved from AutoConfigurationPackages

(Comment from Spring Issue 2721 by wilkinsona, 13. August, 2015)

Igor
  • 1,582
  • 6
  • 19
  • 49