[hibernate-commits] Hibernate SVN: r20738 - in core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153: src/org/hibernate/action and 5 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Sep 28 06:59:37 EDT 2010


Author: stliu
Date: 2010-09-28 06:59:36 -0400 (Tue, 28 Sep 2010)
New Revision: 20738

Added:
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java
Modified:
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
   core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
Log:
JBPAPP-5153 HHH-5490 dirty data be inserted into 2L cache


Property changes on: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153
___________________________________________________________________
Name: svn:ignore
   + .settings
build
.classpath
.project


Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityIdentityInsertAction.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -52,6 +52,7 @@
 			//need to do that here rather than in the save event listener to let
 			//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
 			persister.setIdentifier( instance, generatedId, session.getEntityMode() );
+			getSession().registerInsertedKey( getPersister(), generatedId );
 		}
 
 

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/action/EntityInsertAction.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -70,6 +70,8 @@
 				entry.postUpdate(instance, state, version);
 			}
 			
+			getSession().registerInsertedKey( getPersister(), getId() );
+			
 		}
 
 		final SessionFactoryImplementor factory = getSession().getFactory();

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/SessionImplementor.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -299,4 +299,23 @@
 	 * @return True if the session is closed; false otherwise.
 	 */
 	public boolean isClosed();
+	
+	/**
+	 * Register keys inserted during the current transaction
+	 *
+	 * @param persister The entity persister
+	 * @param id The id
+	 */
+	public void registerInsertedKey(EntityPersister persister, Serializable id);
+
+	/**
+	 * Allows callers to check to see if the identified entity was inserted during the current transaction.
+	 *
+	 * @param persister The entity persister
+	 * @param id The id
+	 *
+	 * @return True if inserted during this transaction, false otherwise.
+	 */
+	public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id);
+
 }

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/engine/TwoPhaseLoad.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -153,19 +153,27 @@
 					session.getEntityMode(), 
 					session.getFactory() 
 				);
-			boolean put = persister.getCache().put( 
-					cacheKey, 
-					persister.getCacheEntryStructure().structure(entry), 
-					session.getTimestamp(),
-					version, 
-					persister.isVersioned() ?
-							persister.getVersionType().getComparator() : 
-							null,
-					useMinimalPuts(session, entityEntry)
-				); //we could use persister.hasLazyProperties() instead of true
-	
-			if ( put && factory.getStatistics().isStatisticsEnabled() ) {
-				factory.getStatisticsImplementor().secondLevelCachePut( persister.getCache().getRegionName() );
+			if (session.wasInsertedDuringTransaction(persister, id)) {
+				persister.getCache().update(cacheKey,
+						persister.getCacheEntryStructure().structure(entry),
+						version, version);
+			} else {
+				boolean put = persister.getCache().put(
+						cacheKey,
+						persister.getCacheEntryStructure().structure(entry),
+						session.getTimestamp(),
+						version,
+						persister.isVersioned() ? persister.getVersionType()
+								.getComparator() : null,
+						useMinimalPuts(session, entityEntry)); // we could use
+																// persister.hasLazyProperties()
+																// instead of
+																// true
+
+				if (put && factory.getStatistics().isStatisticsEnabled()) {
+					factory.getStatisticsImplementor().secondLevelCachePut(
+							persister.getCache().getRegionName());
+				}
 			}
 		}
 	

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/SessionImpl.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -6,6 +6,7 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.sql.Connection;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -420,6 +421,7 @@
 
 	public void afterTransactionCompletion(boolean success, Transaction tx) {
 		log.trace( "after transaction completion" );
+		cleanUpInsertedKeysAfterTransaction();
 		persistenceContext.afterTransactionCompletion();
 		actionQueue.afterTransactionCompletion(success);
 		if ( rootSession == null && tx != null ) {
@@ -1020,7 +1022,48 @@
 
 		flush();
 	}
+	private HashMap insertedKeysMap;
 
+	/**
+	 * {@inheritDoc}
+	 */
+	public void registerInsertedKey(EntityPersister persister, Serializable id) {
+		// we only are about registering these if the persister defines caching
+		if ( persister.hasCache() ) {
+			if ( insertedKeysMap == null ) {
+				insertedKeysMap = new HashMap();
+			}
+			final String rootEntityName = persister.getRootEntityName();
+			List insertedEntityIds = (List)insertedKeysMap.get( rootEntityName );
+			if ( insertedEntityIds == null ) {
+				insertedEntityIds = new ArrayList();
+				insertedKeysMap.put( rootEntityName, insertedEntityIds );
+			}
+			insertedEntityIds.add( id );
+		}
+	}
+	/**
+	 * {@inheritDoc}
+	 */
+	public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
+		// again, we only really care if the entity is cached
+		if ( persister.hasCache() ) {
+			if ( insertedKeysMap != null ) {
+				List insertedEntityIds = (List)insertedKeysMap.get( persister.getRootEntityName() );
+				if ( insertedEntityIds != null ) {
+					return insertedEntityIds.contains( id );
+				}
+			}
+		}
+		return false;
+	}
+
+	private void cleanUpInsertedKeysAfterTransaction() {
+		if ( insertedKeysMap != null ) {
+			insertedKeysMap.clear();
+		}
+	}
+	
 	public Filter getEnabledFilter(String filterName) {
 		checkTransactionSynchStatus();
 		return (Filter) enabledFilters.get(filterName);

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/src/org/hibernate/impl/StatelessSessionImpl.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -627,4 +627,17 @@
 		return result;
 	}
 
+
+	public void registerInsertedKey(EntityPersister persister, Serializable id) {
+		// nothing to do
+		
+	}
+
+
+	public boolean wasInsertedDuringTransaction(EntityPersister persister,
+			Serializable id) {
+		// not in any meaning we need to worry about here.
+		return false;
+	}
+
 }

Added: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml	                        (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.hbm.xml	2010-09-28 10:59:36 UTC (rev 20738)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+  ~ Hibernate, Relational Persistence for Idiomatic Java
+  ~
+  ~ Copyright (c) 2010, 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
+  -->
+<!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.cache">
+
+	<class name="CacheableItem">
+		<id name="id" type="long">
+			<generator class="increment"/>
+		</id>
+        <property name="name" type="string" />
+	</class>
+
+</hibernate-mapping>

Added: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java	                        (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/CacheableItem.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.cache;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class CacheableItem {
+	private Long id;
+	private String name;
+
+	public CacheableItem() {
+	}
+
+	public CacheableItem(String name) {
+		this.name = name;
+	}
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+}

Added: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java	                        (rev 0)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/cache/InsertedDataTest.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -0,0 +1,240 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, 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.cache;
+
+import java.util.Map;
+
+import org.hibernate.Session;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * Tests for handling of data just inserted during a transaction being read from the database
+ * and placed into cache.  Initially these cases went through putFromRead which causes problems because it
+ * loses the context of that data having just been read.
+ *
+ * @author Steve Ebersole
+ */
+public class InsertedDataTest extends FunctionalTestCase {
+	private static final String REGION_NAME = CacheableItem.class.getName();
+
+	public InsertedDataTest(String string) {
+		super( string );
+	}
+
+	public String[] getMappings() {
+		return new String[] { "cache/CacheableItem.hbm.xml" };
+	}
+
+	public String getCacheConcurrencyStrategy() {
+		return "read-write";
+	}
+
+	public void configure(Configuration cfg) {
+		super.configure( cfg );
+		cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
+		cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
+	}
+
+	public void testInsert() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.getTransaction().commit();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 1, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		s.createQuery( "delete CacheableItem" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testInsertWithRollback() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		s.getTransaction().rollback();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 0, cacheMap.size() );
+	}
+
+	public void testInsertThenUpdate() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		item.setName( "new data" );
+		s.getTransaction().commit();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 1, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		s.createQuery( "delete CacheableItem" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testInsertThenUpdateThenRollback() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		item.setName( "new data" );
+		s.getTransaction().rollback();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 0, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		s.createQuery( "delete CacheableItem" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testInsertWithRefresh() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		s.refresh( item );
+		s.getTransaction().commit();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 1, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		s.createQuery( "delete CacheableItem" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testInsertWithRefreshThenRollback() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		s.refresh( item );
+		s.getTransaction().rollback();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 0, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+		s.getTransaction().commit();
+		s.close();
+
+		assertNull( "it should be null", item );
+	}
+
+	public void testInsertWithClear() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		s.clear();
+		s.getTransaction().commit();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 1, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		s.createQuery( "delete CacheableItem" ).executeUpdate();
+		s.getTransaction().commit();
+		s.close();
+	}
+
+	public void testInsertWithClearThenRollback() {
+		getSessions().evict(CacheableItem.class);
+		getSessions().getStatistics().clear();
+
+		Session s = openSession();
+		s.beginTransaction();
+		CacheableItem item = new CacheableItem( "data" );
+		s.save( item );
+		s.flush();
+		s.clear();
+		item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+		s.getTransaction().rollback();
+		s.close();
+
+		Map cacheMap = getSessions().getStatistics().getSecondLevelCacheStatistics( REGION_NAME ).getEntries();
+		assertEquals( 0, cacheMap.size() );
+
+		s = openSession();
+		s.beginTransaction();
+		item = (CacheableItem) s.get( CacheableItem.class, item.getId() );
+		s.getTransaction().commit();
+		s.close();
+
+		assertNull( "it should be null", item );
+	}
+}

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -26,6 +26,8 @@
 	}
 
 	public void testComponentPropertyRef() {
+		Session s = openSession();
+		s.beginTransaction();
 		Person p = new Person();
 		p.setIdentity( new Identity() );
 		Account a = new Account();
@@ -33,13 +35,13 @@
 		a.setOwner(p);
 		p.getIdentity().setName("Gavin");
 		p.getIdentity().setSsn("123-12-1234");
-		Session s = openSession();
-		Transaction tx = s.beginTransaction();
 		s.persist(p);
 		s.persist(a);
-		s.flush();
-		s.clear();
-
+		s.getTransaction().commit();
+		s.close();
+		
+		s = openSession();
+		s.beginTransaction();
 		a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
 		assertTrue( Hibernate.isInitialized( a.getOwner() ) );
 		assertNotNull( a.getOwner() );
@@ -65,7 +67,7 @@
 
 		s.delete( a );
 		s.delete( a.getOwner() );
-		tx.commit();
+		s.getTransaction().commit();
 		s.close();
 	}
 }

Modified: core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java	2010-09-28 10:55:32 UTC (rev 20737)
+++ core/branches/Branch_3_2_4_SP1_CP02_JBPAPP-5153/test/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java	2010-09-28 10:59:36 UTC (rev 20738)
@@ -27,6 +27,8 @@
 	}
 	
 	public void testComponentPropertyRef() {
+		Session s = openSession();
+		s.beginTransaction();
 		Person p = new Person();
 		p.setIdentity( new Identity() );
 		Account a = new Account();
@@ -34,13 +36,13 @@
 		a.setOwner(p);
 		p.getIdentity().setName("Gavin");
 		p.getIdentity().setSsn("123-12-1234");
-		Session s = openSession();
-		Transaction tx = s.beginTransaction();
 		s.persist(p);
 		s.persist(a);
-		s.flush();
-		s.clear();
+		s.getTransaction().commit();
+		s.close();
 		
+		s = openSession();
+		s.beginTransaction();
 		a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
 		assertTrue( Hibernate.isInitialized( a.getOwner() ) );
 		assertNotNull( a.getOwner() );
@@ -66,7 +68,7 @@
 		
 		s.delete( a );
 		s.delete( a.getOwner() );
-		tx.commit();
+		s.getTransaction().commit();
 		s.close();
 	}
 }



More information about the hibernate-commits mailing list