From 85448372eedb0dd41888e36ea300aba2abf975e1 Mon Sep 17 00:00:00 2001
From: pmohan
Date: Fri, 19 Jul 2024 01:22:18 +0700
Subject: [PATCH 1/2] Fix failing schema validation for mysql when boolean/enum
is used
---
.../src/main/resources/config/application.yml.ejs | 3 +++
.../_persistClass_.java.jhi.jakarta_persistence.ejs | 2 +-
.../test/resources/config/application-testdev.yml.ejs | 11 +++++++++++
.../resources/config/application-testprod.yml.ejs | 11 +++++++++++
4 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/generators/server/templates/src/main/resources/config/application.yml.ejs b/generators/server/templates/src/main/resources/config/application.yml.ejs
index 5afe846839db..01fad331516d 100644
--- a/generators/server/templates/src/main/resources/config/application.yml.ejs
+++ b/generators/server/templates/src/main/resources/config/application.yml.ejs
@@ -304,6 +304,9 @@ spring:
# modify fetch size as necessary
hibernate.jdbc.fetch_size: 150
hibernate.criteria.literal_handling_mode: BIND
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ hibernate.type.preferred_boolean_jdbc_type: TINYINT
+ <%_ } _%>
<%_ } _%>
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
diff --git a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs
index e5360b26c18e..69c7b155c4e8 100644
--- a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs
+++ b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs
@@ -60,7 +60,7 @@ import org.hibernate.type.SqlTypes;
@JdbcTypeCode(SqlTypes.VARCHAR)
@Column(name = "<%- field.fieldNameAsDatabaseColumn %>", length = 36<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>)
<%_ } else { _%>
- @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidate === true) { %><% if (field.fieldValidationMaxLength) { %>, length = <%= field.fieldValidateRulesMaxlength %><% } %><% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %><% } %>)
+ @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidate === true) { %><% if (field.fieldValidationMaxLength) { %>, length = <%= field.fieldValidateRulesMaxlength %><% } %><% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %><% } %><% if (field.fieldIsEnum && prodDatabaseTypeMysql) { %>, columnDefinition = "VARCHAR(255)"<% } %>)
<%_ } _%>
<&_ } -&>
<%_ } -%>
diff --git a/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs b/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs
index 837e5111124d..8d81c76a040e 100644
--- a/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs
+++ b/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs
@@ -65,7 +65,11 @@ spring:
jpa:
open-in-view: false
hibernate:
+ <%_ if (devDatabaseTypeMysql) { _%>
+ ddl-auto: validate
+ <%_ } else { _%>
ddl-auto: none
+ <%_ } _%>
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
@@ -75,10 +79,17 @@ spring:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
+ <%_ if (devDatabaseTypeMysql) { _%>
+ hibernate.hbm2ddl.auto: validate
+ <%_ } else { _%>
hibernate.hbm2ddl.auto: none #TODO: temp relief for integration tests, revisit required
+ <%_ } _%>
hibernate.type.preferred_instant_jdbc_type: TIMESTAMP
hibernate.jdbc.time_zone: UTC
hibernate.timezone.default_storage: NORMALIZE
hibernate.query.fail_on_pagination_over_collection_fetch: true
+ <%_ if (devDatabaseTypeMysql) { _%>
+ hibernate.type.preferred_boolean_jdbc_type: TINYINT
+ <%_ } _%>
<%_ } _%>
diff --git a/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs b/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs
index c230b80cdd3f..2221548c453a 100644
--- a/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs
+++ b/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs
@@ -53,7 +53,11 @@ spring:
jpa:
open-in-view: false
hibernate:
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ ddl-auto: validate
+ <%_ } else { _%>
ddl-auto: none
+ <%_ } _%>
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
@@ -63,8 +67,15 @@ spring:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ hibernate.hbm2ddl.auto: validate
+ <%_ } else { _%>
hibernate.hbm2ddl.auto: none #TODO: temp relief for integration tests, revisit required
+ <%_ } _%>
hibernate.type.preferred_instant_jdbc_type: TIMESTAMP
hibernate.jdbc.time_zone: UTC
hibernate.timezone.default_storage: NORMALIZE
hibernate.query.fail_on_pagination_over_collection_fetch: true
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ hibernate.type.preferred_boolean_jdbc_type: TINYINT
+ <%_ } _%>
From 35f8dec865163b4b0201e947a4e56596951e2944 Mon Sep 17 00:00:00 2001
From: pmverma
Date: Fri, 19 Jul 2024 01:22:18 +0700
Subject: [PATCH 2/2] Fix failing schema validation for mysql when boolean/enum
is used
---
.../src/main/resources/config/application.yml.ejs | 3 +++
.../_persistClass_.java.jhi.jakarta_persistence.ejs | 2 +-
.../test/resources/config/application-testdev.yml.ejs | 11 +++++++++++
.../resources/config/application-testprod.yml.ejs | 11 +++++++++++
4 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/generators/server/templates/src/main/resources/config/application.yml.ejs b/generators/server/templates/src/main/resources/config/application.yml.ejs
index 5afe846839db..01fad331516d 100644
--- a/generators/server/templates/src/main/resources/config/application.yml.ejs
+++ b/generators/server/templates/src/main/resources/config/application.yml.ejs
@@ -304,6 +304,9 @@ spring:
# modify fetch size as necessary
hibernate.jdbc.fetch_size: 150
hibernate.criteria.literal_handling_mode: BIND
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ hibernate.type.preferred_boolean_jdbc_type: TINYINT
+ <%_ } _%>
<%_ } _%>
hibernate.query.fail_on_pagination_over_collection_fetch: true
hibernate.query.in_clause_parameter_padding: true
diff --git a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs
index e5360b26c18e..69c7b155c4e8 100644
--- a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs
+++ b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.jakarta_persistence.ejs
@@ -60,7 +60,7 @@ import org.hibernate.type.SqlTypes;
@JdbcTypeCode(SqlTypes.VARCHAR)
@Column(name = "<%- field.fieldNameAsDatabaseColumn %>", length = 36<% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %>)
<%_ } else { _%>
- @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidate === true) { %><% if (field.fieldValidationMaxLength) { %>, length = <%= field.fieldValidateRulesMaxlength %><% } %><% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %><% } %>)
+ @Column(name = "<%- field.fieldNameAsDatabaseColumn %>"<% if (field.fieldValidate === true) { %><% if (field.fieldValidationMaxLength) { %>, length = <%= field.fieldValidateRulesMaxlength %><% } %><% if (field.fieldValidationRequired) { %>, nullable = false<% } %><% if (field.fieldValidationUnique) { %>, unique = true<% } %><% } %><% if (field.fieldIsEnum && prodDatabaseTypeMysql) { %>, columnDefinition = "VARCHAR(255)"<% } %>)
<%_ } _%>
<&_ } -&>
<%_ } -%>
diff --git a/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs b/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs
index 837e5111124d..8d81c76a040e 100644
--- a/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs
+++ b/generators/spring-data-relational/templates/src/test/resources/config/application-testdev.yml.ejs
@@ -65,7 +65,11 @@ spring:
jpa:
open-in-view: false
hibernate:
+ <%_ if (devDatabaseTypeMysql) { _%>
+ ddl-auto: validate
+ <%_ } else { _%>
ddl-auto: none
+ <%_ } _%>
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
@@ -75,10 +79,17 @@ spring:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
+ <%_ if (devDatabaseTypeMysql) { _%>
+ hibernate.hbm2ddl.auto: validate
+ <%_ } else { _%>
hibernate.hbm2ddl.auto: none #TODO: temp relief for integration tests, revisit required
+ <%_ } _%>
hibernate.type.preferred_instant_jdbc_type: TIMESTAMP
hibernate.jdbc.time_zone: UTC
hibernate.timezone.default_storage: NORMALIZE
hibernate.query.fail_on_pagination_over_collection_fetch: true
+ <%_ if (devDatabaseTypeMysql) { _%>
+ hibernate.type.preferred_boolean_jdbc_type: TINYINT
+ <%_ } _%>
<%_ } _%>
diff --git a/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs b/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs
index c230b80cdd3f..2221548c453a 100644
--- a/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs
+++ b/generators/spring-data-relational/templates/src/test/resources/config/application-testprod.yml.ejs
@@ -53,7 +53,11 @@ spring:
jpa:
open-in-view: false
hibernate:
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ ddl-auto: validate
+ <%_ } else { _%>
ddl-auto: none
+ <%_ } _%>
naming:
physical-strategy: org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy
implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
@@ -63,8 +67,15 @@ spring:
hibernate.cache.use_second_level_cache: false
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ hibernate.hbm2ddl.auto: validate
+ <%_ } else { _%>
hibernate.hbm2ddl.auto: none #TODO: temp relief for integration tests, revisit required
+ <%_ } _%>
hibernate.type.preferred_instant_jdbc_type: TIMESTAMP
hibernate.jdbc.time_zone: UTC
hibernate.timezone.default_storage: NORMALIZE
hibernate.query.fail_on_pagination_over_collection_fetch: true
+ <%_ if (prodDatabaseTypeMysql) { _%>
+ hibernate.type.preferred_boolean_jdbc_type: TINYINT
+ <%_ } _%>