Relative Content

Tag Archive for javaspring-boothibernatejpa

Spring boot with JPA(Hibernate) after deployment first save/saveAll (write) to Database is very slow almost 20 seconds. but fetch/get are faster

Spring boot with JPA(Hibernate) after deployment first save/saveAll (write) to Database is very slow almost 20 seconds. but fetch/get are faster . (Running app in docker with 1CPU and 2GB RAM to have same as AWS)
Config are below
“spring.datasource.driver-class-name”: “com.mysql.cj.jdbc.Driver”,
“spring.datasource.password”: “pwd”,
“spring.datasource.url”: “jdbc:mysql://localhost5:3306/db?allowPublicKeyRetrieval=TRUE”,
“spring.datasource.username”: “usr”,
“spring.jpa.properties.hibernate.default_lazy_behavior”: false,
“spring.jpa.properties.hibernate.dialect”: “org.hibernate.dialect.MySQL8Dialect”,
“spring.jpa.properties.hibernate.hbm2ddl.auto”: “none”,
“spring.jpa.show-sql”: true,
“spring.jpa.properties.hibernate.format_sql”: true,
“spring.jpa.properties.hibernate.jdbc.batch_size”: 20,
“spring.jpa.properties.hibernate.order_inserts”: true,
“spring.jpa.properties.hibernate.order_updates”: true,
“spring.datasource.hikari.minimum-idle”: 10,
“spring.datasource.hikari.maximum-pool-size”: 30,
“spring.datasource.hikari.idle-timeout”: 30000,
“spring.datasource.hikari.connection-timeout”: 30000,
“spring.datasource.hikari.max-lifetime”: 1800000,
“spring.datasource.hikari.pool-name”: “HikariCP”,
“spring.main.lazy-initialization”: false,
“spring.datasource.initialization-mode”:”always”,
“spring.datasource.hikari.initialization-fail-timeout”:0,
“spring.jpa.hibernate.ddl-auto”:”validate”

JPA generates wrong FK

It seems that I made a mistake somewhere but I can not see where.
JPA insists to generate a unique constraint on a FK of one-to-many relationship on the child side. This constraint prevents me to insert more then one record in the child table.