diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java index b0e607ce46294..c4b37abeeb778 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/JpaJandexScavenger.java @@ -301,7 +301,7 @@ private void collectHbmXmlEmbeddedTypes(Collector collector, String packagePrefi // The call to 'enlistExplicitClass' above may not // detect that this class is an entity if it is not annotated collector.entityTypes.add(name); - collectHbmXmlEmbeddedTypes(collector, packagePrefix, attributes); + collectHbmXmlEmbeddedTypes(collector, packagePrefix, compositeAttribute.getAttributes()); } } } diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/HbmXmlComplexFileTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/HbmXmlComplexFileTest.java new file mode 100644 index 0000000000000..3118289293213 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/HbmXmlComplexFileTest.java @@ -0,0 +1,52 @@ +package io.quarkus.hibernate.orm.xml.hbm; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.transaction.Transactional; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.SchemaUtil; +import io.quarkus.hibernate.orm.SmokeTestUtils; +import io.quarkus.test.QuarkusUnitTest; + +public class HbmXmlComplexFileTest { + @RegisterExtension + final static QuarkusUnitTest TEST = new QuarkusUnitTest() + .withApplicationRoot(jar -> jar + .addClass(SmokeTestUtils.class) + .addClass(SchemaUtil.class) + .addClass(NonAnnotatedComplexEntity.class) + .addClass(NonAnnotatedComponentEntity.class) + .addAsResource("application-mapping-files-my-complex-hbm-xml.properties", "application.properties") + .addAsResource("META-INF/hbm-complex.xml", "my-complex-hbm.xml")); + + @Inject + EntityManagerFactory entityManagerFactory; + + @Inject + EntityManager entityManager; + + @Test + @Transactional + public void ormXmlTakenIntoAccount() { + assertThat(SchemaUtil.getColumnNames(entityManagerFactory, NonAnnotatedComplexEntity.class)) + .contains("thename") + .doesNotContain("name"); + assertThat(SchemaUtil.getColumnNames(entityManagerFactory, NonAnnotatedComplexEntity.class)) + .contains("value"); + } + + @Test + @Transactional + public void smokeTest() { + SmokeTestUtils.testSimplePersistRetrieveUpdateDelete(entityManager, + NonAnnotatedComplexEntity.class, NonAnnotatedComplexEntity::new, + NonAnnotatedComplexEntity::getId, NonAnnotatedComplexEntity::setName, NonAnnotatedComplexEntity::getName); + } + +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/NonAnnotatedComplexEntity.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/NonAnnotatedComplexEntity.java new file mode 100644 index 0000000000000..63baa6c33495b --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/NonAnnotatedComplexEntity.java @@ -0,0 +1,41 @@ +package io.quarkus.hibernate.orm.xml.hbm; + +public class NonAnnotatedComplexEntity { + + private long id; + + private String name; + + private NonAnnotatedComponentEntity value; + + public NonAnnotatedComplexEntity() { + } + + public NonAnnotatedComplexEntity(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public NonAnnotatedComponentEntity getValue() { + return value; + } + + public void setValue(NonAnnotatedComponentEntity value) { + this.value = value; + } +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/NonAnnotatedComponentEntity.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/NonAnnotatedComponentEntity.java new file mode 100644 index 0000000000000..0e87cc9e00e02 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/xml/hbm/NonAnnotatedComponentEntity.java @@ -0,0 +1,14 @@ +package io.quarkus.hibernate.orm.xml.hbm; + +public class NonAnnotatedComponentEntity { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/extensions/hibernate-orm/deployment/src/test/resources/META-INF/hbm-complex.xml b/extensions/hibernate-orm/deployment/src/test/resources/META-INF/hbm-complex.xml new file mode 100644 index 0000000000000..7d95ba47a760f --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/resources/META-INF/hbm-complex.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/extensions/hibernate-orm/deployment/src/test/resources/application-mapping-files-my-complex-hbm-xml.properties b/extensions/hibernate-orm/deployment/src/test/resources/application-mapping-files-my-complex-hbm-xml.properties new file mode 100644 index 0000000000000..6f6e899da694d --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/resources/application-mapping-files-my-complex-hbm-xml.properties @@ -0,0 +1,7 @@ +quarkus.datasource.db-kind=h2 +quarkus.datasource.jdbc.url=jdbc:h2:mem:test + +quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect +#quarkus.hibernate-orm.log.sql=true +quarkus.hibernate-orm.database.generation=drop-and-create +quarkus.hibernate-orm.mapping-files=my-complex-hbm.xml