reproducer of hhh-18236

This commit is contained in:
Nicolas Lalevée 2024-06-28 19:46:02 +02:00
parent 1c1572b88e
commit 69dd220433
4 changed files with 91 additions and 1 deletions

View File

@ -0,0 +1,36 @@
package org.hibernate.orm.test.jpa;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import org.hibernate.annotations.DynamicInsert;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE_BOOK")
@DiscriminatorValue("MAIN")
@DynamicInsert
public class Book {
@Id
public String isbn;
public String title;
@Enumerated(EnumType.STRING)
@Column(name = "TYPE_BOOK", insertable = false, updatable = false, nullable = false)
protected BookType bookType;
public Book() {
}
public Book(String isbn, String title) {
this.isbn = isbn;
this.title = title;
}
}

View File

@ -0,0 +1,6 @@
package org.hibernate.orm.test.jpa;
public enum BookType {
MAIN,
SUB
}

View File

@ -0,0 +1,24 @@
package org.hibernate.orm.test.jpa;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import org.hibernate.annotations.DynamicInsert;
@Entity
@DiscriminatorValue("SUB")
@DynamicInsert
public class SubBook extends Book {
@Column
public String subdata;
public SubBook() {
}
public SubBook(String isbn, String title, String subdata) {
this.isbn = isbn;
this.title = title;
this.subdata = subdata;
}
}

View File

@ -32,8 +32,10 @@ import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.PostgresPlusDialect;
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.Item;
import org.hibernate.orm.test.jpa.SubBook;
import org.hibernate.orm.test.jpa.Wallet;
import org.hibernate.stat.Statistics;
@ -64,7 +66,9 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase {
Distributor.class,
Wallet.class,
Employee.class,
Contractor.class
Contractor.class,
Book.class,
SubBook.class,
};
}
@ -1582,4 +1586,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();
}
}
}