Xavi
Xavi

Reputation: 87

maven sprinbootest junit 5 is not populating properly database with dates

I'm working with springboot and JPA and I have a problem to pass tests with maven. When I run from IDE they passed.

The problem is related with dates.I have this insert at resources/data.sql:

INSERT INTO orders (order_id, number, client_id, created_on) values (2, '0002', 1, '2021-11-21 16:12:20.414' );

but when I recover order_id = 2 the created_on date is null

This only happens when I run with mvn install, Running the test directly from the IDE has the date properly set.

pom dependencies:

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

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>


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

    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>

any idea?

thanks

Upvotes: 0

Views: 29

Answers (1)

bkomo
bkomo

Reputation: 85

It is hard to say without seeing tests, but I think, the problem lays in date format in DB and date format which you pass through test. Database receives incorrect format, so it puts in null. If you could show some code, maybe I can be of more help.

Upvotes: 1

Related Questions