Skip to content

Commit

Permalink
Fix hbm.xml builds with CompositeAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
digsb authored and gsmet committed Jan 7, 2022
1 parent 2d3a968 commit 70a1b1d
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="io.quarkus.hibernate.orm.xml.hbm.NonAnnotatedComplexEntity">
<id name="id">
<generator class="identity"/>
</id>
<property name="name" column="thename"/>
<component name="value" class="io.quarkus.hibernate.orm.xml.hbm.NonAnnotatedComponentEntity" lazy="false">
<property name="value">
<column name="value"/>
</property>
</component>
</class>
</hibernate-mapping>
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 70a1b1d

Please sign in to comment.