HHH-2350 : tests for 2nd level cache broken for non-inverse bidirectional one-to-many relation
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19080 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
a2c73b365b
commit
dfc4310739
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.onetomany;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.junit.functional.FunctionalTestCase;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
|
||||
/**
|
||||
* @author Burkhard Graves, Gail Badner
|
||||
*/
|
||||
|
||||
public abstract class AbstractRecursiveBidirectionalOneToManyTest extends FunctionalTestCase {
|
||||
|
||||
/*
|
||||
* What is done:
|
||||
* ___ ___
|
||||
* | | | |
|
||||
* -> 1 -> 1
|
||||
* | -transform-> / \
|
||||
* 2 2 3
|
||||
* |
|
||||
* 3
|
||||
*
|
||||
*/
|
||||
|
||||
public AbstractRecursiveBidirectionalOneToManyTest(String str) {
|
||||
super(str);
|
||||
}
|
||||
|
||||
public org.hibernate.classic.Session openSession() {
|
||||
org.hibernate.classic.Session s = super.openSession();
|
||||
s.setCacheMode( getSessionCacheMode() );
|
||||
return s;
|
||||
}
|
||||
|
||||
protected abstract CacheMode getSessionCacheMode();
|
||||
|
||||
public String[] getMappings() {
|
||||
return new String[] { "onetomany/Node.hbm.xml" };
|
||||
}
|
||||
|
||||
public void testOneToManyMoveElement() {
|
||||
init();
|
||||
transformMove();
|
||||
check();
|
||||
delete();
|
||||
}
|
||||
|
||||
public void testOneToManyReplaceList() {
|
||||
init();
|
||||
transformReplace();
|
||||
check();
|
||||
delete();
|
||||
}
|
||||
|
||||
void init() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Node node1 = new Node( 1 );
|
||||
Node node2 = new Node( 2 );
|
||||
Node node3 = new Node( 3 );
|
||||
|
||||
node1.addSubNode( node2 );
|
||||
node2.addSubNode( node3 );
|
||||
|
||||
s.save(node1);
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
void transformMove() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Node node3 = (Node) s.load(Node.class, new Integer(3));
|
||||
Node node2 = node3.getParentNode();
|
||||
Node node1 = node2.getParentNode();
|
||||
|
||||
node2.removeSubNode( node3 );
|
||||
node1.addSubNode( node3 );
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
void transformReplace() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
Node node3 = (Node) s.load(Node.class, new Integer(3));
|
||||
Node node2 = node3.getParentNode();
|
||||
Node node1 = node2.getParentNode();
|
||||
|
||||
node2.removeSubNode( node3 );
|
||||
node1.setSubNodes( new ArrayList() );
|
||||
node1.addSubNode( node2 );
|
||||
node1.addSubNode( node3 );
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
void check() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Node node3 = (Node) s.get(Node.class, new Integer(3));
|
||||
|
||||
// fails with 2nd level cache enabled
|
||||
assertEquals(1, node3.getParentNode().getId().intValue());
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
void delete() {
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Node node1 = ( Node ) s.get( Node.class, new Integer( 1 ) );
|
||||
s.delete( node1 );
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.onetomany">
|
||||
<class name="Node"
|
||||
table="Node">
|
||||
<cache usage="read-write" region="Node.entities"/>
|
||||
<id name="id" column="id" type="java.lang.Integer">
|
||||
<!--<generator class="native"/> -->
|
||||
</id>
|
||||
<many-to-one name="parentNode"
|
||||
class="Node"
|
||||
column="node_id"
|
||||
lazy="proxy"
|
||||
not-null="false"
|
||||
insert="false"
|
||||
update="false"
|
||||
|
||||
/>
|
||||
<list name="subNodes" cascade="all">
|
||||
<key column="node_id"/>
|
||||
<list-index column="idx"/>
|
||||
<one-to-many class="Node"/>
|
||||
</list>
|
||||
</class>
|
||||
</hibernate-mapping>
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.onetomany;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Node implements Serializable {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Node parentNode;
|
||||
private List subNodes = new ArrayList();
|
||||
|
||||
public Node() {
|
||||
}
|
||||
|
||||
public Node(int id) {
|
||||
setId( id );
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Node getParentNode() {
|
||||
return parentNode;
|
||||
}
|
||||
|
||||
public void setParentNode(Node parentNode) {
|
||||
this.parentNode = parentNode;
|
||||
}
|
||||
|
||||
public List getSubNodes() {
|
||||
return subNodes;
|
||||
}
|
||||
|
||||
public void setSubNodes(List subNodes) {
|
||||
this.subNodes = subNodes;
|
||||
}
|
||||
|
||||
public void addSubNode(Node subNode) {
|
||||
subNodes.add( subNode );
|
||||
subNode.setParentNode( this );
|
||||
}
|
||||
|
||||
public void removeSubNode(Node subNode) {
|
||||
subNodes.remove( subNode );
|
||||
subNode.setParentNode( null );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.onetomany;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
|
||||
/**
|
||||
* @author Burkhard Graves, Gail Badner
|
||||
*/
|
||||
|
||||
public class RecursiveBidirectionalOneToManyCacheTest extends AbstractRecursiveBidirectionalOneToManyTest {
|
||||
|
||||
/*
|
||||
* What is done:
|
||||
* ___ ___
|
||||
* | | | |
|
||||
* -> 1 -> 1
|
||||
* | -transform-> / \
|
||||
* 2 2 3
|
||||
* |
|
||||
* 3
|
||||
*
|
||||
* Commenting out
|
||||
* @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
|
||||
* in Node.java makes the assertion true (in check() below).
|
||||
*/
|
||||
|
||||
public RecursiveBidirectionalOneToManyCacheTest(String str) {
|
||||
super(str);
|
||||
}
|
||||
|
||||
protected CacheMode getSessionCacheMode() {
|
||||
return CacheMode.NORMAL;
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new FunctionalTestClassTestSuite( RecursiveBidirectionalOneToManyCacheTest.class );
|
||||
}
|
||||
|
||||
public void testOneToManyMoveElement() {
|
||||
reportSkip( "non-inverse one-to-many known to fail with 2nd-level cache", "cache support");
|
||||
}
|
||||
|
||||
// HHH-2350
|
||||
public void testOneToManyMoveElementFailureExpected() {
|
||||
super.testOneToManyMoveElement();
|
||||
}
|
||||
|
||||
public void testOneToManyReplaceList() {
|
||||
reportSkip( "non-inverse one-to-many known to fail with 2nd-level cache", "cache support");
|
||||
}
|
||||
|
||||
// HHH-2350
|
||||
public void testOneToManyReplaceListFailureExpected() {
|
||||
super.testOneToManyReplaceList();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.onetomany;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.junit.functional.FunctionalTestCase;
|
||||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
|
||||
/**
|
||||
* @author Burkhard Graves, Gail Badner
|
||||
*/
|
||||
|
||||
public class RecursiveBidirectionalOneToManyNoCacheTest extends AbstractRecursiveBidirectionalOneToManyTest {
|
||||
|
||||
/*
|
||||
* What is done:
|
||||
* ___ ___
|
||||
* | | | |
|
||||
* -> 1 -> 1
|
||||
* | -transform-> / \
|
||||
* 2 2 3
|
||||
* |
|
||||
* 3
|
||||
*
|
||||
* Commenting out
|
||||
* @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
|
||||
* in Node.java makes the assertion true (in check() below).
|
||||
*/
|
||||
|
||||
public RecursiveBidirectionalOneToManyNoCacheTest(String str) {
|
||||
super(str);
|
||||
}
|
||||
|
||||
public String getCacheConcurrencyStrategy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected CacheMode getSessionCacheMode() {
|
||||
return CacheMode.IGNORE;
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new FunctionalTestClassTestSuite( RecursiveBidirectionalOneToManyNoCacheTest.class );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue