[hibernate-commits] Hibernate SVN: r19515 - in core/branches/Branch_3_3_2_GA_CP: core/src/main/java/org/hibernate/engine/jdbc and 4 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sat May 15 03:12:18 EDT 2010


Author: stliu
Date: 2010-05-15 03:12:17 -0400 (Sat, 15 May 2010)
New Revision: 19515

Added:
   core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml
   core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.java
   core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Country.java
   core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Org.java
   core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java
Modified:
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transform/RootEntityResultTransformer.java
Log:
JBPAPP-3737 HHH-3220 Patch to prevent org.hibernate.AssertionFailure: possible non-threadsafe access to the session error caused by stateless sessions

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -148,7 +148,7 @@
 	public void addEntity(EntityUniqueKey euk, Object entity);
 
 	/**
-	 * Retreive the EntityEntry representation of the given entity.
+	 * Retrieve the EntityEntry representation of the given entity.
 	 *
 	 * @param entity The entity for which to locate the EntityEntry.
 	 * @return The EntityEntry for the given entity.
@@ -437,7 +437,7 @@
 	public void setFlushing(boolean flushing);
 
 	/**
-	 * Call this before begining a two-phase load
+	 * Call this before beginning a two-phase load
 	 */
 	public void beforeLoad();
 
@@ -445,8 +445,12 @@
 	 * Call this after finishing a two-phase load
 	 */
 	public void afterLoad();
-
+	
 	/**
+	 * 
+	 */
+	public boolean isLoadFinished();
+	/**
 	 * Returns a string representation of the object.
 	 *
 	 * @return a string representation of the object.

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -174,19 +174,15 @@
 	}
 
 	public void addUnownedCollection(CollectionKey key, PersistentCollection collection) {
-		if (unownedCollections==null) {
+		if (unownedCollections == null) {
 			unownedCollections = new HashMap(8);
 		}
 		unownedCollections.put(key, collection);
 	}
 	
 	public PersistentCollection useUnownedCollection(CollectionKey key) {
-		if (unownedCollections==null) {
-			return null;
-		}
-		else {
-			return (PersistentCollection) unownedCollections.remove(key);
-		}
+		return ( unownedCollections == null ) ? null : (PersistentCollection) unownedCollections
+				.remove( key );
 	}
 	
 	/**
@@ -382,7 +378,7 @@
 	}
 
 	/**
-	 * Retreive the EntityEntry representation of the given entity.
+	 * Retrieve the EntityEntry representation of the given entity.
 	 *
 	 * @param entity The entity for which to locate the EntityEntry.
 	 * @return The EntityEntry for the given entity.
@@ -671,16 +667,12 @@
 	 * third argument (the entity associated with the key) if no proxy exists. Init
 	 * the proxy to the target implementation, if necessary.
 	 */
-	public Object proxyFor(EntityPersister persister, EntityKey key, Object impl) 
-	throws HibernateException {
-		if ( !persister.hasProxy() ) return impl;
-		Object proxy = proxiesByKey.get(key);
-		if ( proxy != null ) {
-			return narrowProxy(proxy, persister, key, impl);
-		}
-		else {
+	public Object proxyFor( EntityPersister persister, EntityKey key, Object impl )
+			throws HibernateException {
+		if ( !persister.hasProxy() )
 			return impl;
-		}
+		Object proxy = proxiesByKey.get( key );
+		return ( proxy != null ) ? narrowProxy( proxy, persister, key, impl ) : impl;
 	}
 
 	/**
@@ -874,7 +866,6 @@
 		}
 	}
 
-
 	/**
 	 * Get the <tt>PersistentCollection</tt> object for an array
 	 */
@@ -1046,7 +1037,7 @@
 	}
 
 	/**
-	 * Call this before begining a two-phase load
+	 * Call this before beginning a two-phase load
 	 */
 	public void beforeLoad() {
 		loadCounter++;
@@ -1058,7 +1049,10 @@
 	public void afterLoad() {
 		loadCounter--;
 	}
-
+	
+	public boolean isLoadFinished() {
+		return loadCounter == 0;
+	}
 	/**
 	 * Returns a string representation of the object.
 	 *

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/jdbc/LobCreationContext.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -26,8 +26,6 @@
 import java.sql.Connection;
 import java.sql.SQLException;
 
-import org.hibernate.JDBCException;
-import org.hibernate.exception.SQLExceptionConverter;
 
 /**
  * Provides callback access into the context in which the LOB is to be created.  Mainly this is useful

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/FetchingScrollableResultsImpl.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -24,7 +24,6 @@
  */
 package org.hibernate.impl;
 
-import org.apache.tools.ant.taskdefs.condition.IsReference;
 import org.hibernate.HibernateException;
 import org.hibernate.MappingException;
 import org.hibernate.exception.JDBCExceptionHelper;

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/SessionImpl.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -77,7 +77,6 @@
 import org.hibernate.engine.StatefulPersistenceContext;
 import org.hibernate.engine.Status;
 import org.hibernate.engine.jdbc.LobCreationContext;
-import org.hibernate.engine.jdbc.LobCreationContext.Callback;
 import org.hibernate.engine.query.FilterQueryPlan;
 import org.hibernate.engine.query.HQLQueryPlan;
 import org.hibernate.engine.query.NativeSQLQueryPlan;

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -177,7 +177,9 @@
 		errorIfClosed();
 		Object result = getFactory().getEntityPersister(entityName)
 				.load(id, null, lockMode, this);
-		temporaryPersistenceContext.clear();
+		if ( temporaryPersistenceContext.isLoadFinished() ) {
+			temporaryPersistenceContext.clear();
+		}
 		return result;
 	}
 
@@ -275,6 +277,8 @@
 		}
 		// otherwise immediately materialize it
 		return get( entityName, id );
+//		return getFactory().getEntityPersister(entityName).load(id,
+//			    null, LockMode.NONE, this);
 	}
 
 	public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -30,7 +30,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Iterator;
 
 import org.hibernate.HibernateException;
 import org.hibernate.LockMode;

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transform/RootEntityResultTransformer.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transform/RootEntityResultTransformer.java	2010-05-14 13:38:39 UTC (rev 19514)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transform/RootEntityResultTransformer.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -24,7 +24,6 @@
  */
 package org.hibernate.transform;
 
-import java.util.List;
 import java.io.Serializable;
 
 /**

Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml	                        (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.hbm.xml	2010-05-15 07:12:17 UTC (rev 19515)
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!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.stateless">
+
+	<class name="Contact">
+		<id name="id">
+			<generator class="native" />
+		</id>
+		<many-to-one name="org" lazy="false" fetch="join" />
+	</class>
+
+	<class name="Org">
+		<id name="id">
+			<generator class="native" />
+		</id>
+		<many-to-one name="country" lazy="false" fetch="join" />
+	</class>
+
+	<class name="Country">
+		<id name="id">
+			<generator class="native" />
+		</id>
+	</class>
+
+</hibernate-mapping>
\ No newline at end of file

Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.java	                        (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Contact.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -0,0 +1,47 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.stateless;
+
+/**
+ * 
+ * @author stliu
+ */
+public class Contact {
+	private Integer id;
+	public Integer getId() {
+		return id;
+	}
+	public void setId( Integer id ) {
+		this.id = id;
+	}
+	public Org getOrg() {
+		return org;
+	}
+	public void setOrg( Org org ) {
+		this.org = org;
+	}
+	private Org org;
+	
+}

Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Country.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Country.java	                        (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Country.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -0,0 +1,13 @@
+package org.hibernate.test.stateless;
+
+public class Country {
+	private Integer id;
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+}

Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Org.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Org.java	                        (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/Org.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -0,0 +1,23 @@
+package org.hibernate.test.stateless;
+
+public class Org {
+	private Integer id;
+	private Country country;
+
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	public Country getCountry() {
+		return country;
+	}
+
+	public void setCountry(Country country) {
+		this.country = country;
+	}
+
+}

Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java	                        (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/stateless/StatelessSessionQueryTest.java	2010-05-15 07:12:17 UTC (rev 19515)
@@ -0,0 +1,117 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.stateless;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.FetchMode;
+import org.hibernate.Session;
+import org.hibernate.StatelessSession;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * 
+ * @author stliu
+ */
+public class StatelessSessionQueryTest extends FunctionalTestCase {
+
+	public StatelessSessionQueryTest( String string ) {
+		super( string );
+	}
+
+	public void testCriteria() {
+		TestData testData=new TestData();
+		testData.createData();
+		StatelessSession s = getSessions().openStatelessSession();
+		assertEquals( 1, s.createCriteria( Contact.class ).list().size() );
+		s.close();
+		testData.cleanData();
+	}
+
+	public void testCriteriaWithSelectFetchMode() {
+		TestData testData=new TestData();
+		testData.createData();
+		StatelessSession s = getSessions().openStatelessSession();
+		assertEquals( 1, s.createCriteria( Contact.class ).setFetchMode( "org", FetchMode.SELECT )
+				.list().size() );
+		s.close();
+		testData.cleanData();
+	}
+
+	public void testHQL() {
+		TestData testData=new TestData();
+		testData.createData();
+		StatelessSession s = getSessions().openStatelessSession();
+		assertEquals( 1, s.createQuery( "from Contact c join fetch c.org join fetch c.org.country" )
+				.list().size() );
+		s.close();
+		testData.cleanData();
+	}
+	private class TestData{
+		List list = new ArrayList();
+		public void createData(){
+			Session session = openSession();
+			Transaction tx = session.beginTransaction();
+			Country usa = new Country();
+			session.save( usa );
+			list.add( usa );
+			Org disney = new Org();
+			disney.setCountry( usa );
+			session.save( disney );
+			list.add( disney );
+			Contact waltDisney = new Contact();
+			waltDisney.setOrg( disney );
+			session.save( waltDisney );
+			list.add( waltDisney );
+			tx.commit();
+			session.close();
+		}
+		public void cleanData(){
+			Session session = openSession();
+			Transaction tx = session.beginTransaction();
+			for(Object obj: list){
+				session.delete( obj );
+			}
+			tx.commit();
+			session.close();
+		}
+	}
+
+
+	@Override
+	public void configure( Configuration cfg ) {
+		super.configure( cfg );
+		cfg.setProperty( Environment.MAX_FETCH_DEPTH, "1" );
+	}
+
+	public String[] getMappings() {
+		return new String[] { "stateless/Contact.hbm.xml" };
+	}
+
+}



More information about the hibernate-commits mailing list