diff --git a/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/BaseChild.java b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/BaseChild.java new file mode 100644 index 0000000000..6d6ee8eff2 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/BaseChild.java @@ -0,0 +1,61 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.lazynocascadecache; + +/** + * @author Vasily Kochnev + */ +public class BaseChild { + private Long id; + + private BaseChild dependency; + + /** + * @return Entity identifier. + */ + public Long getId() { + return id; + } + + /** + * @param id Identifier to set. + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return Child dependency + */ + public BaseChild getDependency() { + return dependency; + } + + /** + * @param dependency Dependency to set. + */ + public void setDependency(BaseChild dependency) { + this.dependency = dependency; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Child.java b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Child.java new file mode 100644 index 0000000000..2ec94c4745 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Child.java @@ -0,0 +1,45 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.lazynocascadecache; + +/** + * @author Vasily Kochnev + */ +public class Child extends BaseChild { + private String name; + + /** + * @return Name of the child. + */ + public String getName() { + return name; + } + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/LazyNoCascadeCacheTest.java b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/LazyNoCascadeCacheTest.java new file mode 100644 index 0000000000..34b82b49bc --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/LazyNoCascadeCacheTest.java @@ -0,0 +1,60 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.lazynocascadecache; + +import org.hibernate.Session; +import org.hibernate.Transaction; + +import org.junit.Test; + +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; + +/** + * @author Vasily Kochnev + */ +public class LazyNoCascadeCacheTest extends BaseCoreFunctionalTestCase { + public String[] getMappings() { + return new String[] {"lazynocascadecache/Parent.hbm.xml"}; + } + + @Test + public void testNoCascadeCache() { + Parent parent = new Parent(); + + BaseChild firstChild = new BaseChild(); + parent.getChildren().add( firstChild ); + + Child secondChild = new Child(); + secondChild.setName( "SecondChildName" ); + parent.getChildren().add( secondChild );//Dependency child must go after dependent in collection + + firstChild.setDependency( secondChild ); + + Session s = openSession(); + Transaction t = s.beginTransaction(); + s.merge( parent ); + t.commit(); + s.close(); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Parent.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Parent.hbm.xml new file mode 100644 index 0000000000..507b3448ca --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Parent.hbm.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Parent.java b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Parent.java new file mode 100644 index 0000000000..d318abb1df --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/lazynocascadecache/Parent.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.lazynocascadecache; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * @author Vasily Kochnev + */ +public class Parent { + private Long id; + + // LinkedHashSet used for the reason to force the specific order of elements in collection + private Set children = new LinkedHashSet(); + + /** + * @return Entity identifier. + */ + public Long getId() { + return id; + } + + /** + * @param id Identifier to set. + */ + public void setId(Long id) { + this.id = id; + } + + /** + * @return Set of children entities. + */ + public Set getChildren() { + return children; + } + + /** + * @param children Set of children entities to set. + */ + public void setChildren(Set children) { + this.children = children; + } +}