generator-jhipster: MySQL - Entity with LocalDate: one-day bug
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!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 33 (30 by maintainers)
@DanielFran : no worry about JHipster, take care of yourself, it’s more important my friend !
@DanielFran best wishes.
take care @DanielFran ! Yes I’ll submit a PR. Thx.
It should be OK for the next release: https://github.com/mysql/mysql-connector-j/pull/53
A ticket on MySQL Connector/J is opened here: https://bugs.mysql.com/bug.php?id=99713 (about the exception on storing date with the connector 8.0.20) It is “verfied”. So I think if we have a version 8.0.21 it should work as 8.0.20 should fix the “one day bug” in a proper way.