From 0ef8d1c7cf24eb3ca2373c6862f8a523b23eb6e8 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 28 Oct 2024 14:53:15 +0100 Subject: [PATCH] Avoid isPersisted being saved in elasticsearch index (#27704) Fix #27686 --- .../templates/src/main/java/_package_/domain/User.java.ejs | 5 ++--- .../_persistClass_.java.jhi.spring_data_persistable.ejs | 6 ++++++ .../domain/_persistClass_.java.jhi.spring_data_reactive.ejs | 3 +-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/generators/spring-boot/templates/src/main/java/_package_/domain/User.java.ejs b/generators/spring-boot/templates/src/main/java/_package_/domain/User.java.ejs index 31b62df864cd..6e4dcc4a34cf 100644 --- a/generators/spring-boot/templates/src/main/java/_package_/domain/User.java.ejs +++ b/generators/spring-boot/templates/src/main/java/_package_/domain/User.java.ejs @@ -41,7 +41,6 @@ import org.hibernate.annotations.CacheConcurrencyStrategy; <%_ } _%> <%_ if (databaseTypeSql && reactive) { _%> import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Table; <%_ if (requiresPersistableImplementation) { _%> @@ -395,7 +394,7 @@ public class <%= user.persistClass %><% if (generateSpringAuditor) { %> extends @BatchSize(size = 20) <%_ } _%> <%_ if (databaseTypeSql && reactive) { _%> - @Transient + @org.springframework.data.annotation.Transient <%_ } _%> <%_ if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { _%> private Set authorities = new HashSet<>(); @@ -413,7 +412,7 @@ public class <%= user.persistClass %><% if (generateSpringAuditor) { %> extends <%_ } _%> <%_ if (databaseTypeSql && reactive && requiresPersistableImplementation) { _%> - @Transient + @org.springframework.data.annotation.Transient private boolean isPersisted; <%_ } _%> diff --git a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs index 5186a2a8d178..78019cb9abc8 100644 --- a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs +++ b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_persistable.ejs @@ -36,7 +36,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; <&_ } -&> <&_ if (fragment.classAdditionalFieldsSection) { -&> + @org.springframework.data.annotation.Transient +<%_ if (!reactive) { _%> @Transient +<%_ } _%> private boolean isPersisted; <&_ } -&> @@ -48,7 +51,10 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; } <%_ } -%> + @org.springframework.data.annotation.Transient +<%_ if (!reactive) { _%> @Transient +<%_ } _%> @Override public boolean isNew() { return !this.isPersisted; diff --git a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_reactive.ejs b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_reactive.ejs index 7655cae15704..704ee5018be1 100644 --- a/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_reactive.ejs +++ b/generators/spring-data-relational/templates/src/main/java/_package_/_entityPackage_/domain/_persistClass_.java.jhi.spring_data_reactive.ejs @@ -22,7 +22,6 @@ -%> <&_ if (fragment.importSection) { -&> import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.Transient; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Table; <&_ } -&> @@ -55,7 +54,7 @@ import org.springframework.data.relational.core.mapping.Table; <%_ for (const relationship of relationships) { _%> <&_ if (fragment.relationship<%- relationship.relationshipNameCapitalized %>AnnotationSection) { -&> - @Transient + @org.springframework.data.annotation.Transient <&_ } -&> <%_ } -%>