From 20bc96baefd540f67d606fbe5ca066ad01880ac5 Mon Sep 17 00:00:00 2001 From: hugothomas Date: Wed, 13 Dec 2023 11:17:47 +0100 Subject: [PATCH] Enable composer for embeddable: adding test --- .../graph/repository/GeneratedEntityGraphTest.java | 8 ++++++++ .../data/jpa/graph/generator/MetamodelAttribute.java | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/GeneratedEntityGraphTest.java b/core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/GeneratedEntityGraphTest.java index 803b361..39535b2 100644 --- a/core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/GeneratedEntityGraphTest.java +++ b/core/src/test/java/com/cosium/spring/data/jpa/entity/graph/repository/GeneratedEntityGraphTest.java @@ -8,6 +8,7 @@ import com.github.springtestdbunit.annotation.DatabaseSetup; import javax.inject.Inject; import org.hibernate.Hibernate; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; @@ -43,5 +44,12 @@ void test() { assertThat(Hibernate.isInitialized(product.getMaker().getCountry())).isTrue(); } + @Test + @DisplayName("EntityGraph with embedded part is well generated") + @Transactional + void test2() { + ProductEntityGraph.____().tracking().creator().____.tracking().modifier().____.____(); + } + public interface ProductRepository extends EntityGraphCrudRepository {} } diff --git a/generator/src/main/java/com/cosium/spring/data/jpa/graph/generator/MetamodelAttribute.java b/generator/src/main/java/com/cosium/spring/data/jpa/graph/generator/MetamodelAttribute.java index 4ab0b63..f8ad4f5 100644 --- a/generator/src/main/java/com/cosium/spring/data/jpa/graph/generator/MetamodelAttribute.java +++ b/generator/src/main/java/com/cosium/spring/data/jpa/graph/generator/MetamodelAttribute.java @@ -75,9 +75,7 @@ public Optional jpaTarget() { return Optional.empty(); } - if ((targetTypeElement.getAnnotation(Entity.class) == null - && targetTypeElement.getAnnotation(Embeddable.class) == null) - && !pluralAttribute) { + if (!isRelatedToEntityConcept(targetTypeElement) && !pluralAttribute) { return Optional.empty(); } @@ -85,4 +83,9 @@ public Optional jpaTarget() { new MetamodelAttributeTarget( variableElement.getSimpleName().toString(), targetTypeElement)); } + + private boolean isRelatedToEntityConcept(TypeElement targetTypeElement) { + return targetTypeElement.getAnnotation(Entity.class) != null + || targetTypeElement.getAnnotation(Embeddable.class) != null; + } }