From 8b190dbbd0b3df842d697cc74ed668af712504a3 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Thu, 3 May 2018 08:24:02 +0300 Subject: [PATCH] HHH-12470 - Batching statements fails for delete Add replicating test case --- .../batch/BatchingInheritanceDeleteTest.java | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/batch/BatchingInheritanceDeleteTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/batch/BatchingInheritanceDeleteTest.java b/hibernate-core/src/test/java/org/hibernate/test/batch/BatchingInheritanceDeleteTest.java new file mode 100644 index 0000000000..5dd7942574 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/batch/BatchingInheritanceDeleteTest.java @@ -0,0 +1,235 @@ +/* + * 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.batch; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; +import javax.persistence.OneToMany; + +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; + +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; + +/** + * @author Vlad Mihalcea + */ +@TestForIssue( jiraKey = "HHH-12470" ) +public class BatchingInheritanceDeleteTest extends BaseCoreFunctionalTestCase { + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ + Foo.class, + Bar.class, + Baz.class + }; + } + + @Override + protected void configure(Configuration configuration) { + super.configure( configuration ); + configuration.setProperty( AvailableSettings.STATEMENT_BATCH_SIZE, "25" ); + } + + @Test + @FailureExpected( jiraKey = "HHH-12470" ) + public void testDelete() { + doInHibernate( this::sessionFactory, s -> { + Bar bar = new Bar("bar"); + + Foo foo = new Foo("foo"); + foo.setBar(bar); + + s.persist(foo); + s.persist(bar); + + s.flush(); + + s.remove(foo); + s.remove(bar); + + s.flush(); + + assertThat(s.find(Foo.class, foo.getId()), nullValue()); + assertThat(s.find(Bar.class, bar.getId()), nullValue()); + } ); + } + + @Entity(name = "Bar") + public static class Bar extends AbstractBar { + + @Column(nullable = false) + private String name; + + @OneToMany(cascade = CascadeType.ALL) + List bazList = new ArrayList<>(); + + public Bar() { + super(); + } + + public Bar(final String name) { + super(); + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public List getBazList() { + return bazList; + } + + public void setBazList(final List bazList) { + this.bazList = bazList; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Bar [name=").append(name).append("]"); + return builder.toString(); + } + } + + @Entity(name = "Baz") + public static class Baz { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column(nullable = false) + private String name; + + public Baz() { + super(); + } + + public Baz(final String name) { + super(); + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Bar [name=").append(name).append("]"); + return builder.toString(); + } + } + + @Entity(name = "Foo") + @Inheritance(strategy = InheritanceType.JOINED) + public static class Foo extends AbstractFoo { + + public Foo() { + super(); + } + + public Foo(final String name) { + super(); + this.name = name; + } + + @Column(name = "NAME") + private String name; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "BAR_ID") + private Bar bar; + + public Bar getBar() { + return bar; + } + + public void setBar(final Bar bar) { + this.bar = bar; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + } + + @Entity(name = "AbstractBar") + @Inheritance(strategy = InheritanceType.JOINED) + public static class AbstractBar { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + } + + @MappedSuperclass + public static class AbstractFoo { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + } +}