From 6d54383ca919b50eb7211a07327b0fa94297c261 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Tue, 17 Apr 2018 10:02:28 +0300 Subject: [PATCH] HHH-12407 - order_inserts: StackOverflowError when flushing a session Add test that proves the issue does not replicate anymore --- ...eringWithBaseClassReferencingSubclass.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBaseClassReferencingSubclass.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBaseClassReferencingSubclass.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBaseClassReferencingSubclass.java new file mode 100644 index 0000000000..1b6b5b9c36 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBaseClassReferencingSubclass.java @@ -0,0 +1,113 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.insertordering; + +import java.sql.SQLException; +import java.util.Map; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; + +import org.hibernate.cfg.Environment; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; +import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; +import org.junit.Test; + +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; + +/** + * @author Vlad Mihalcea + */ +@TestForIssue(jiraKey = "HHH-12407") +public class InsertOrderingWithBaseClassReferencingSubclass + extends BaseNonConfigCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + OwningTable.class, + TableB.class, + TableA.class, + LinkTable.class + }; + } + + @Override + protected void addSettings(Map settings) { + settings.put( Environment.ORDER_INSERTS, "true" ); + settings.put( Environment.STATEMENT_BATCH_SIZE, "10" ); + } + + @Test + public void testBatching() throws SQLException { + doInHibernate( this::sessionFactory, session -> { + OwningTable rec_owningTable = new OwningTable(); + session.persist(rec_owningTable); + + session.flush(); + + TableB rec_tableB = new TableB(); + rec_tableB.owning = rec_owningTable; + session.persist(rec_tableB); + + TableA rec_tableA = new TableA(); + rec_tableA.owning = rec_owningTable; + session.persist(rec_tableA); + + LinkTable rec_link = new LinkTable(); + rec_link.refToA = rec_tableA; + rec_link.refToB = rec_tableB; + + session.persist(rec_link); + } ); + + } + + @Entity(name = "RootTable") + @Inheritance(strategy = InheritanceType.JOINED) + public abstract static class RootTable { + @Id + @GeneratedValue + public int sysId; + } + + @Entity(name = "OwnedTable") + public abstract static class OwnedTable extends RootTable { + @ManyToOne + public OwningTable owning; + } + + @Entity(name = "OwningTable") + public static class OwningTable extends OwnedTable { + } + + @Entity(name = "TableA") + public static class TableA extends OwnedTable { + } + + @Entity + public static class TableB extends OwnedTable { + } + + @Entity(name = "LinkTable") + public static class LinkTable { + @Id + @GeneratedValue + public int sysId; + + @ManyToOne + public TableA refToA; + + @ManyToOne + public TableB refToB; + } +}