diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/BarOne.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/BarOne.java new file mode 100644 index 0000000000..f97d79ba9d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/BarOne.java @@ -0,0 +1,22 @@ +package org.hibernate.test.bytecode.enhancement.lazy.HHH_10708; + +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +class BarOne { + static final String FOO = "foo"; + + @Id + @GeneratedValue + int id; + + @ManyToOne + @Cache( usage = CacheConcurrencyStrategy.READ_WRITE ) + FooOne foo; +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/BarTwo.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/BarTwo.java new file mode 100644 index 0000000000..01889f185d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/BarTwo.java @@ -0,0 +1,20 @@ +package org.hibernate.test.bytecode.enhancement.lazy.HHH_10708; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import java.util.HashSet; +import java.util.Set; + +@Entity +class BarTwo { + + @Id + @GeneratedValue + int id; + + @ManyToMany( fetch = FetchType.LAZY, targetEntity = FooTwo.class ) + Set foos = new HashSet<>(); +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/FooOne.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/FooOne.java new file mode 100644 index 0000000000..8323fd30e9 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/FooOne.java @@ -0,0 +1,23 @@ +package org.hibernate.test.bytecode.enhancement.lazy.HHH_10708; + +import org.hibernate.annotations.Cascade; +import org.hibernate.annotations.CascadeType; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import java.util.HashSet; +import java.util.Set; + +@Entity +class FooOne { + + @Id + @GeneratedValue + int id; + + @OneToMany( orphanRemoval = true, mappedBy = BarOne.FOO, targetEntity = BarOne.class ) + @Cascade( CascadeType.ALL ) + Set bars = new HashSet<>(); +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/FooTwo.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/FooTwo.java new file mode 100644 index 0000000000..7f18a664df --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/FooTwo.java @@ -0,0 +1,13 @@ +package org.hibernate.test.bytecode.enhancement.lazy.HHH_10708; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +class FooTwo { + + @Id + @GeneratedValue + int id; +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteOneTestTask.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteOneTestTask.java index bbdab72880..3c37e6e234 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteOneTestTask.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteOneTestTask.java @@ -6,19 +6,7 @@ */ package org.hibernate.test.bytecode.enhancement.lazy.HHH_10708; -import java.util.HashSet; -import java.util.Set; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; - import org.hibernate.Session; -import org.hibernate.annotations.Cache; -import org.hibernate.annotations.CacheConcurrencyStrategy; -import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.CascadeType; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; @@ -29,7 +17,7 @@ public class UnexpectedDeleteOneTestTask extends AbstractEnhancerTestTask { private int fooId; public Class[] getAnnotatedClasses() { - return new Class[] {Foo.class, Bar.class}; + return new Class[] {FooOne.class, BarOne.class}; } public void prepare() { @@ -41,9 +29,9 @@ public class UnexpectedDeleteOneTestTask extends AbstractEnhancerTestTask { Session s = getFactory().openSession(); s.beginTransaction(); - Bar bar1 = new Bar(); - Bar bar2 = new Bar(); - Foo foo = new Foo(); + BarOne bar1 = new BarOne(); + BarOne bar2 = new BarOne(); + FooOne foo = new FooOne(); s.save( bar1 ); s.save( bar2 ); s.save( foo ); @@ -60,7 +48,7 @@ public class UnexpectedDeleteOneTestTask extends AbstractEnhancerTestTask { Session s = getFactory().openSession(); s.beginTransaction(); - Foo foo = s.get( Foo.class, fooId ); + FooOne foo = s.get( FooOne.class, fooId ); // accessing the collection results in an exception foo.bars.size(); @@ -73,24 +61,4 @@ public class UnexpectedDeleteOneTestTask extends AbstractEnhancerTestTask { protected void cleanup() { } - @Entity static class Bar { - static final String FOO = "foo"; - - @Id @GeneratedValue - int id; - - @ManyToOne @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) - Foo foo; - } - - @Entity static class Foo { - - @Id @GeneratedValue - int id; - - @OneToMany(orphanRemoval = true, mappedBy = Bar.FOO, targetEntity = Bar.class) - @Cascade(CascadeType.ALL) - Set bars = new HashSet<>(); - } - } \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTwoTestTask.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTwoTestTask.java index e38623dfc4..f1fa6993bf 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTwoTestTask.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/HHH_10708/UnexpectedDeleteTwoTestTask.java @@ -6,14 +6,6 @@ */ package org.hibernate.test.bytecode.enhancement.lazy.HHH_10708; -import java.util.HashSet; -import java.util.Set; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToMany; - import org.hibernate.Session; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; @@ -24,10 +16,10 @@ import org.junit.Assert; public class UnexpectedDeleteTwoTestTask extends AbstractEnhancerTestTask { - private Bar myBar; + private BarTwo myBar; public Class[] getAnnotatedClasses() { - return new Class[] {Foo.class, Bar.class}; + return new Class[] {FooTwo.class, BarTwo.class}; } public void prepare() { @@ -40,9 +32,9 @@ public class UnexpectedDeleteTwoTestTask extends AbstractEnhancerTestTask { Session s = getFactory().openSession(); s.beginTransaction(); - Bar bar = new Bar(); - Foo foo1 = new Foo(); - Foo foo2 = new Foo(); + BarTwo bar = new BarTwo(); + FooTwo foo1 = new FooTwo(); + FooTwo foo2 = new FooTwo(); s.save( bar ); s.save( foo1 ); s.save( foo2 ); @@ -73,7 +65,7 @@ public class UnexpectedDeleteTwoTestTask extends AbstractEnhancerTestTask { s = getFactory().openSession(); s.beginTransaction(); - Bar bar = s.get( Bar.class, myBar.id ); + BarTwo bar = s.get( BarTwo.class, myBar.id ); Assert.assertFalse( bar.foos.isEmpty() ); s.flush(); @@ -84,19 +76,4 @@ public class UnexpectedDeleteTwoTestTask extends AbstractEnhancerTestTask { protected void cleanup() { } - @Entity static class Bar { - - @Id @GeneratedValue - int id; - - @ManyToMany(fetch = FetchType.LAZY, targetEntity = Foo.class) - Set foos = new HashSet<>(); - } - - @Entity static class Foo { - - @Id @GeneratedValue - int id; - } - } \ No newline at end of file