Skip to content

Commit

Permalink
Enable composer for embeddable: adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
hugothomas committed Dec 13, 2023
1 parent 75b44bf commit 20bc96b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Product, Long> {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,17 @@ public Optional<MetamodelAttributeTarget> jpaTarget() {
return Optional.empty();
}

if ((targetTypeElement.getAnnotation(Entity.class) == null
&& targetTypeElement.getAnnotation(Embeddable.class) == null)
&& !pluralAttribute) {
if (!isRelatedToEntityConcept(targetTypeElement) && !pluralAttribute) {
return Optional.empty();
}

return Optional.of(
new MetamodelAttributeTarget(
variableElement.getSimpleName().toString(), targetTypeElement));
}

private boolean isRelatedToEntityConcept(TypeElement targetTypeElement) {
return targetTypeElement.getAnnotation(Entity.class) != null
|| targetTypeElement.getAnnotation(Embeddable.class) != null;
}
}

0 comments on commit 20bc96b

Please sign in to comment.