diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/DeleteMultiLevelOrphansTest.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/DeleteMultiLevelOrphansTest.java new file mode 100644 index 0000000000..a172ea2d17 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/DeleteMultiLevelOrphansTest.java @@ -0,0 +1,170 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.bidirectional.multilevelcascade; + +import java.util.List; + +import org.junit.Test; + +import org.hibernate.Session; +import org.hibernate.test.orphan.one2one.fk.bidirectional.Employee; +import org.hibernate.test.orphan.one2one.fk.bidirectional.EmployeeInfo; +import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +/** + * @author Steve Ebersole + * @author Gail Badner + */ +public class DeleteMultiLevelOrphansTest extends BaseCoreFunctionalTestCase { + + private void createData() { + Preisregelung preisregelung = new Preisregelung(); + preisregelung.setId( 17960L ); + + Tranchenmodell tranchenmodell = new Tranchenmodell(); + tranchenmodell.setId( 1951L ); + + Tranche tranche1 = new Tranche(); + tranche1.setId( 1951L); + + Tranche tranche2 = new Tranche(); + tranche2.setId( 1952L); + + preisregelung.setTranchenmodell( tranchenmodell ); + tranchenmodell.setPreisregelung( preisregelung ); + + tranchenmodell.getTranchen().add( tranche1 ); + tranche1.setTranchenmodell( tranchenmodell ); + tranchenmodell.getTranchen().add( tranche2 ); + tranche2.setTranchenmodell( tranchenmodell ); + + Session session = openSession(); + session.beginTransaction(); + session.save( preisregelung ); + session.getTransaction().commit(); + session.close(); + } + + private void cleanupData() { + Session session = openSession(); + session.beginTransaction(); + session.createQuery( "delete Tranche" ).executeUpdate(); + session.createQuery( "delete Tranchenmodell" ).executeUpdate(); + session.createQuery( "delete Preisregelung" ).executeUpdate(); + session.getTransaction().commit(); + session.close(); + } + + @Test + @TestForIssue( jiraKey = "HHH-9091") + @FailureExpected( jiraKey = "HHH-9091") + public void testOrphanedWhileManaged() { + createData(); + + Session session = openSession(); + session.beginTransaction(); + List results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 1, results.size() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + Preisregelung preisregelung = ( Preisregelung ) results.get( 0 ); + assertNotNull( preisregelung.getTranchenmodell() ); + preisregelung.setTranchenmodell( null ); + session.getTransaction().commit(); + session.close(); + + session = openSession(); + session.beginTransaction(); + + preisregelung = ( Preisregelung ) session.get( Preisregelung.class, preisregelung.getId() ); + assertNull( preisregelung.getTranchenmodell() ); + results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 0, results.size() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + + session.getTransaction().commit(); + session.close(); + + cleanupData(); + } + + @Test + @TestForIssue( jiraKey = "HHH-9091") + @FailureExpected( jiraKey = "HHH-9091") + public void testReplacedWhileManaged() { + createData(); + + Session session = openSession(); + session.beginTransaction(); + List results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 1, results.size() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + Preisregelung preisregelung = ( Preisregelung ) results.get( 0 ); + assertNotNull( preisregelung.getTranchenmodell() ); + + // Replace with a new Tranchenmodell instance + Tranchenmodell tranchenmodellNew = new Tranchenmodell(); + tranchenmodellNew.setId( 1952L ); + preisregelung.setTranchenmodell(tranchenmodellNew ); + tranchenmodellNew.setPreisregelung( preisregelung ); + session.getTransaction().commit(); + session.close(); + + session = openSession(); + session.beginTransaction(); + results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 1, results.size() ); + Tranchenmodell tranchenmodellQueried = (Tranchenmodell) results.get( 0 ); + assertEquals( tranchenmodellNew.getId(), tranchenmodellQueried.getId() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + Preisregelung preisregelung1Queried = (Preisregelung) results.get( 0 ); + assertEquals( tranchenmodellQueried, preisregelung1Queried.getTranchenmodell() ); + results = session.createQuery( "from Tranche" ).list(); + assertEquals( 0, results.size() ); + + session.getTransaction().commit(); + session.close(); + + cleanupData(); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ + Preisregelung.class, + Tranche.class, + Tranchenmodell.class + }; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Preisregelung.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Preisregelung.java new file mode 100644 index 0000000000..ea9ff3fb9b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Preisregelung.java @@ -0,0 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.bidirectional.multilevelcascade; + +import javax.persistence.*; + +@Entity +public class Preisregelung { + @Id + private Long id; + + @OneToOne(mappedBy = "preisregelung", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) + private Tranchenmodell tranchenmodell; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Tranchenmodell getTranchenmodell() { + return tranchenmodell; + } + + public void setTranchenmodell(Tranchenmodell tranchenmodell) { + this.tranchenmodell = tranchenmodell; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Tranche.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Tranche.java new file mode 100644 index 0000000000..90e286cb78 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Tranche.java @@ -0,0 +1,53 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.bidirectional.multilevelcascade; + +import javax.persistence.*; + +@Entity +public class Tranche { + + @Id + private Long id; + + @ManyToOne(optional = false, fetch = FetchType.EAGER) + private Tranchenmodell tranchenmodell; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Tranchenmodell getTranchenmodell() { + return tranchenmodell; + } + + public void setTranchenmodell(Tranchenmodell tranchenmodell) { + this.tranchenmodell = tranchenmodell; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Tranchenmodell.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Tranchenmodell.java new file mode 100644 index 0000000000..ec9e7b0aae --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/multilevelcascade/Tranchenmodell.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.bidirectional.multilevelcascade; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +public class Tranchenmodell { + + @Id + private Long id; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "tranchenmodell", fetch = FetchType.LAZY, orphanRemoval = true) + private List tranchen = new ArrayList(); + + @OneToOne(optional = true, fetch = FetchType.LAZY) + private Preisregelung preisregelung; + + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public List getTranchen() { + return tranchen; + } + + public Preisregelung getPreisregelung() { + return preisregelung; + } + + public void setPreisregelung(Preisregelung preisregelung) { + this.preisregelung = preisregelung; + } + + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/DeleteMultiLevelOrphansTest.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/DeleteMultiLevelOrphansTest.java new file mode 100644 index 0000000000..673616ea8e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/DeleteMultiLevelOrphansTest.java @@ -0,0 +1,165 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.reversed.bidirectional.multilevelcascade; + +import java.util.List; + +import org.junit.Test; + +import org.hibernate.Session; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +/** + * @author Steve Ebersole + * @author Gail Badner + */ +public class DeleteMultiLevelOrphansTest extends BaseCoreFunctionalTestCase { + + private void createData() { + Preisregelung preisregelung = new Preisregelung(); + preisregelung.setId( 17960L ); + + Tranchenmodell tranchenmodell = new Tranchenmodell(); + tranchenmodell.setId( 1951L ); + + Tranche tranche1 = new Tranche(); + tranche1.setId( 1951L); + + Tranche tranche2 = new Tranche(); + tranche2.setId( 1952L); + + preisregelung.setTranchenmodell( tranchenmodell ); + tranchenmodell.setPreisregelung( preisregelung ); + + tranchenmodell.getTranchen().add( tranche1 ); + tranche1.setTranchenmodell( tranchenmodell ); + tranchenmodell.getTranchen().add( tranche2 ); + tranche2.setTranchenmodell( tranchenmodell ); + + Session session = openSession(); + session.beginTransaction(); + session.save( preisregelung ); + session.getTransaction().commit(); + session.close(); + } + + private void cleanupData() { + Session session = openSession(); + session.beginTransaction(); + session.createQuery( "delete Tranche" ).executeUpdate(); + session.createQuery( "delete Preisregelung" ).executeUpdate(); + session.createQuery( "delete Tranchenmodell" ).executeUpdate(); + session.getTransaction().commit(); + session.close(); + } + + @Test + @TestForIssue( jiraKey = "HHH-9091") + public void testOrphanedWhileManaged() { + createData(); + + Session session = openSession(); + session.beginTransaction(); + List results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 1, results.size() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + Preisregelung preisregelung = (Preisregelung) results.get( 0 ); + assertNotNull( preisregelung.getTranchenmodell() ); + preisregelung.setTranchenmodell( null ); + session.getTransaction().commit(); + session.close(); + + session = openSession(); + session.beginTransaction(); + + preisregelung = (Preisregelung) session.get( Preisregelung.class, preisregelung.getId() ); + assertNull( preisregelung.getTranchenmodell() ); + results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 0, results.size() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + + session.getTransaction().commit(); + session.close(); + + cleanupData(); + } + + @Test + @TestForIssue( jiraKey = "HHH-9091") + public void testReplacedWhileManaged() { + createData(); + + Session session = openSession(); + session.beginTransaction(); + List results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 1, results.size() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + Preisregelung preisregelung = (Preisregelung) results.get( 0 ); + assertNotNull( preisregelung.getTranchenmodell() ); + + // Replace with a new Tranchenmodell instance + Tranchenmodell tranchenmodellNew = new Tranchenmodell(); + tranchenmodellNew.setId( 1952L ); + preisregelung.setTranchenmodell( tranchenmodellNew ); + tranchenmodellNew.setPreisregelung( preisregelung ); + session.getTransaction().commit(); + session.close(); + + session = openSession(); + session.beginTransaction(); + results = session.createQuery( "from Tranchenmodell" ).list(); + assertEquals( 1, results.size() ); + Tranchenmodell tranchenmodellQueried = (Tranchenmodell) results.get( 0 ); + assertEquals( tranchenmodellNew.getId(), tranchenmodellQueried.getId() ); + results = session.createQuery( "from Preisregelung" ).list(); + assertEquals( 1, results.size() ); + Preisregelung preisregelung1Queried = (Preisregelung) results.get( 0 ); + assertEquals( tranchenmodellQueried, preisregelung1Queried.getTranchenmodell() ); + results = session.createQuery( "from Tranche" ).list(); + assertEquals( 0, results.size() ); + + session.getTransaction().commit(); + session.close(); + + cleanupData(); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[]{ + Preisregelung.class, + Tranche.class, + Tranchenmodell.class + }; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Preisregelung.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Preisregelung.java new file mode 100644 index 0000000000..a86f89f25f --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Preisregelung.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.reversed.bidirectional.multilevelcascade; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity +public class Preisregelung { + @Id + private Long id; + + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) + private Tranchenmodell tranchenmodell; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Tranchenmodell getTranchenmodell() { + return tranchenmodell; + } + + public void setTranchenmodell(Tranchenmodell tranchenmodell) { + this.tranchenmodell = tranchenmodell; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Tranche.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Tranche.java new file mode 100644 index 0000000000..421c07b0a2 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Tranche.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.reversed.bidirectional.multilevelcascade; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Tranche { + + @Id + private Long id; + + @ManyToOne(optional = false, fetch = FetchType.EAGER) + private Tranchenmodell tranchenmodell; + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Tranchenmodell getTranchenmodell() { + return tranchenmodell; + } + + public void setTranchenmodell(Tranchenmodell tranchenmodell) { + this.tranchenmodell = tranchenmodell; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Tranchenmodell.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Tranchenmodell.java new file mode 100644 index 0000000000..4d5ae5a3c0 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/multilevelcascade/Tranchenmodell.java @@ -0,0 +1,70 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.orphan.one2one.fk.reversed.bidirectional.multilevelcascade; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + +@Entity +public class Tranchenmodell { + + @Id + private Long id; + + @OneToMany(cascade = CascadeType.ALL, mappedBy = "tranchenmodell", fetch = FetchType.LAZY, orphanRemoval = true) + private List tranchen = new ArrayList(); + + @OneToOne(mappedBy="tranchenmodell", optional = true, fetch = FetchType.LAZY) + private Preisregelung preisregelung; + + + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public List getTranchen() { + return tranchen; + } + + public Preisregelung getPreisregelung() { + return preisregelung; + } + + public void setPreisregelung(Preisregelung preisregelung) { + this.preisregelung = preisregelung; + } + + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/DeleteOneToManyOrphansTest.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/DeleteOneToManyOrphansTest.java index a7bf344376..9475e53055 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/DeleteOneToManyOrphansTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/DeleteOneToManyOrphansTest.java @@ -78,7 +78,7 @@ public class DeleteOneToManyOrphansTest extends BaseCoreFunctionalTestCase { assertEquals( 1, results.size() ); Product product = ( Product ) results.get( 0 ); assertEquals( 1, product.getFeatures().size() ); - product.getFeatures().clear();; + product.getFeatures().clear(); session.getTransaction().commit(); session.close(); @@ -132,7 +132,6 @@ public class DeleteOneToManyOrphansTest extends BaseCoreFunctionalTestCase { cleanupData(); } - @Test @TestForIssue( jiraKey = "HHH-9330") public void testReplacedWhileManaged() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/Feature.java b/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/Feature.java index 6d535b0b1d..193746b751 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/Feature.java +++ b/hibernate-core/src/test/java/org/hibernate/test/orphan/onetomany/Feature.java @@ -41,6 +41,13 @@ public class Feature { private String name; + public Feature() { + } + + public Feature(Product product) { + this.product = product; + } + public Long getId() { return id; }