question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL - Entity with LocalDate: one-day bug

See original GitHub issue
Overview of the issue

Following this ticket: https://github.com/jhipster/generator-jhipster/issues/11734

In a MySQL application, when you save an entity with LocalDate, the result is not correct:

  • save with 2020/05/08
  • result: 2020/05/07
Motivation for or Use Case

The result should be correct.

Reproduce the error

I pushed this project to reproduce easily: https://github.com/pascalgrimaud/jhipster-burger-11740

git clone https://github.com/pascalgrimaud/jhipster-burger-11740
cd jhipster-burger-11740
npm ci
docker-compose -f src/main/docker/mysql.yml up -d
./mvnw

Then, go to Beer entity Create a new entity Check the drinkDate

Related issues

https://github.com/jhipster/generator-jhipster/issues/11734

Suggest a Fix

Not sure at all about this solution :

diff --git a/src/main/java/io/github/pascalgrimaud/BurgerApp.java b/src/main/java/io/github/pascalgrimaud/BurgerApp.java
index 6236c6d..3a0b37c 100644
--- a/src/main/java/io/github/pascalgrimaud/BurgerApp.java
+++ b/src/main/java/io/github/pascalgrimaud/BurgerApp.java
@@ -5,6 +5,7 @@ import io.github.pascalgrimaud.config.ApplicationProperties;
 import io.github.jhipster.config.DefaultProfileUtil;
 import io.github.jhipster.config.JHipsterConstants;
 
+import java.util.TimeZone;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,6 +42,8 @@ public class BurgerApp {
      */
     @PostConstruct
     public void initApplication() {
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
         Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles());
         if (activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(JHipsterConstants.SPRING_PROFILE_PRODUCTION)) {
             log.error("You have misconfigured your application! It should not run " +
JHipster Version(s)

6.8.0 and maybe less

JHipster Version(s)
burger@0.0.1-SNAPSHOT /home/pgrimaud/tmp/11-burger
└── (empty)

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "io.github.pascalgrimaud",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "6.8.0",
    "applicationType": "monolith",
    "baseName": "burger",
    "packageName": "io.github.pascalgrimaud",
    "packageFolder": "io/github/pascalgrimaud",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "YourJWTSecretKeyWasReplacedByThisMeaninglessTextByTheJHipsterInfoCommandForObviousSecurityReasons",
    "embeddableLaunchScript": false,
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "angularX",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1588964185564,
    "testFrameworks": ["protractor"],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [],
    "enableTranslation": true,
    "nativeLanguage": "en",
    "languages": ["en"],
    "blueprints": [],
    "prettierJava": true
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Beer {
  name String,
  drinkDate LocalDate
}
dto Beer with mapstruct
service Beer with serviceClass

Environment and Tools

openjdk version “11.0.7” 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)

git version 2.26.2

node: v12.16.1

npm: 6.14.2

yeoman: 3.1.1

yarn: 1.22.4

Docker version 19.03.8, build afacb8b7f0

docker-compose version 1.21.2, build a133471

identical .jhipster/Beer.json INFO! Congratulations, JHipster execution is complete!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:33 (30 by maintainers)

github_iconTop GitHub Comments

2reactions
pascalgrimaudcommented, Oct 18, 2020

@DanielFran : no worry about JHipster, take care of yourself, it’s more important my friend !

2reactions
mshimacommented, Oct 18, 2020

@DanielFran best wishes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring data query for localdate returns wrong entries
There was a bug in the MySQL Connector/J earlier than version 8.0.22. Updating to 8.0.22 will fix the issue. From the 8.0.22 changelog:....
Read more >
99487: Mysql connector for java 8.0.20 shifts back LocalDate ...
Bug #99487, Mysql connector for java 8.0.20 shifts back LocalDate by one day when queried. Submitted: 8 May 2020 10:39, Modified: 12 May...
Read more >
LocalDate MySQL issue - wrong day persisted - Jmix Forum
Docker is required for this, as it spins up a testcontainers mysql database. Please run the test in TimezoneMysqlBugApplicationTests and have a ...
Read more >
LocalDateTime (Java Platform SE 8 ) - Oracle Help Center
public final class LocalDateTime extends Object implements Temporal, TemporalAdjuster, ChronoLocalDateTime<LocalDate>, Serializable.
Read more >
Impala Date and Time Functions | 6.3.x
For example, 11:59 PM on one day and 12:01 on the next day represent a ... This change lets the date and time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found