reproducer of HHH-18677

This commit is contained in:
Nicolas Lalevée 2024-10-01 10:25:43 +02:00
parent d94a2a7ea9
commit 13c8f809af
5 changed files with 102 additions and 1 deletions

View File

@ -0,0 +1,35 @@
package org.hibernate.orm.test.jpa;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="type")
@DiscriminatorValue("MAIN")
public class Book {
@Id
public String isbn;
public String title;
@Column(insertable = false, updatable = false, nullable = false)
protected String type;
@Embedded
public EmbeddedDataColumn myData;
public Book() {
}
public Book(String isbn, String title) {
this.isbn = isbn;
this.title = title;
}
}

View File

@ -0,0 +1,11 @@
package org.hibernate.orm.test.jpa;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
@Embeddable
public class EmbeddedDataColumn {
@Column
public String embeddedData = null;
}

View File

@ -0,0 +1,17 @@
package org.hibernate.orm.test.jpa;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
@Entity
@DiscriminatorValue("SUB")
public class SubBook extends Book {
public SubBook() {
super();
}
public SubBook(String isbn, String title) {
super(isbn, title);
}
}

View File

@ -0,0 +1,10 @@
package org.hibernate.orm.test.jpa;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
@Embeddable
public class ValueEmbeddedDataColumn<T> extends EmbeddedDataColumn {
@Column
public T myvalue;
}

View File

@ -36,8 +36,12 @@ import org.hibernate.dialect.PostgresPlusDialect;
import org.hibernate.dialect.SybaseDialect; import org.hibernate.dialect.SybaseDialect;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.orm.test.jpa.Book;
import org.hibernate.orm.test.jpa.Distributor; import org.hibernate.orm.test.jpa.Distributor;
import org.hibernate.orm.test.jpa.EmbeddedDataColumn;
import org.hibernate.orm.test.jpa.Item; import org.hibernate.orm.test.jpa.Item;
import org.hibernate.orm.test.jpa.SubBook;
import org.hibernate.orm.test.jpa.ValueEmbeddedDataColumn;
import org.hibernate.orm.test.jpa.Wallet; import org.hibernate.orm.test.jpa.Wallet;
import org.hibernate.stat.Statistics; import org.hibernate.stat.Statistics;
@ -70,7 +74,11 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
Distributor.class, Distributor.class,
Wallet.class, Wallet.class,
Employee.class, Employee.class,
Contractor.class Contractor.class,
Book.class,
SubBook.class,
EmbeddedDataColumn.class,
ValueEmbeddedDataColumn.class,
}; };
} }
@ -1658,4 +1666,24 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
entityManager.close(); entityManager.close();
} }
} }
@Test
@TestForIssue(jiraKey = "HHH-18236")
public void test18236() {
EntityManager em = getOrCreateEntityManager();
try {
em.getTransaction().begin();
em.persist( new Book("9781932394153", "Hibernate in Action") );
em.flush();
List results = em.createNativeQuery("select b.* from book b", Book.class).getResultList();
assertEquals(1, results.size());
}
finally {
em.getTransaction().rollback();
em.close();
}
}
} }