From 13c8f809af49917799dbbe79ea4b4f9eea0a4262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Laleve=CC=81e?= Date: Tue, 1 Oct 2024 10:25:43 +0200 Subject: [PATCH] reproducer of HHH-18677 --- .../java/org/hibernate/orm/test/jpa/Book.java | 35 +++++++++++++++++++ .../orm/test/jpa/EmbeddedDataColumn.java | 11 ++++++ .../org/hibernate/orm/test/jpa/SubBook.java | 17 +++++++++ .../orm/test/jpa/ValueEmbeddedDataColumn.java | 10 ++++++ .../orm/test/jpa/query/QueryTest.java | 30 +++++++++++++++- 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/Book.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EmbeddedDataColumn.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/SubBook.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ValueEmbeddedDataColumn.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/Book.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/Book.java new file mode 100644 index 0000000000..e613e342f9 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/Book.java @@ -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; + } +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EmbeddedDataColumn.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EmbeddedDataColumn.java new file mode 100644 index 0000000000..a039c2fa4c --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/EmbeddedDataColumn.java @@ -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; +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/SubBook.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/SubBook.java new file mode 100644 index 0000000000..aa1e55237f --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/SubBook.java @@ -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); + } +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ValueEmbeddedDataColumn.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ValueEmbeddedDataColumn.java new file mode 100644 index 0000000000..9bdba227fe --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/ValueEmbeddedDataColumn.java @@ -0,0 +1,10 @@ +package org.hibernate.orm.test.jpa; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; + +@Embeddable +public class ValueEmbeddedDataColumn extends EmbeddedDataColumn { + @Column + public T myvalue; +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryTest.java index d4d45dac68..9ecae19452 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/QueryTest.java @@ -36,8 +36,12 @@ import org.hibernate.dialect.PostgresPlusDialect; import org.hibernate.dialect.SybaseDialect; import org.hibernate.engine.spi.SessionFactoryImplementor; 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.EmbeddedDataColumn; 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.stat.Statistics; @@ -70,7 +74,11 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { Distributor.class, Wallet.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(); } } + + @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(); + } + + } + }