[hibernate-commits] Hibernate SVN: r20654 - in core/branches/Branch_3_5: core/src/main/java/org/hibernate/engine and 6 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Sep 16 16:22:18 EDT 2010


Author: steve.ebersole at jboss.com
Date: 2010-09-16 16:22:17 -0400 (Thu, 16 Sep 2010)
New Revision: 20654

Added:
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java
Modified:
   core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
   core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityInsertAction.java
   core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/SessionImplementor.java
   core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
   core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/SessionImpl.java
   core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
   core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
   core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java
Log:
HHH-5490 - dirty data be inserted into 2L cache 


Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -75,6 +75,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 );
+			getSession().registerInsertedKey( getPersister(), generatedId );
 		}
 
 

Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityInsertAction.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/action/EntityInsertAction.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -92,7 +92,7 @@
 				}
 				entry.postUpdate(instance, state, version);
 			}
-			
+			getSession().registerInsertedKey( getPersister(), getId() );
 		}
 
 		final SessionFactoryImplementor factory = getSession().getFactory();

Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/SessionImplementor.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/SessionImplementor.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -365,4 +365,22 @@
 	 * should never be null.
 	 */
 	public LoadQueryInfluencers getLoadQueryInfluencers();
+
+	/**
+	 * 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_5/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -32,6 +32,7 @@
 import org.hibernate.CacheMode;
 import org.hibernate.HibernateException;
 import org.hibernate.LockMode;
+import org.hibernate.cache.access.SoftLock;
 import org.hibernate.proxy.HibernateProxy;
 import org.hibernate.cache.CacheKey;
 import org.hibernate.cache.entry.CacheEntry;
@@ -177,17 +178,32 @@
 					session.getEntityMode(), 
 					session.getFactory() 
 			);
-			boolean put = persister.getCacheAccessStrategy().putFromLoad(
-					cacheKey,
-					persister.getCacheEntryStructure().structure( entry ),
-					session.getTimestamp(),
-					version,
-					useMinimalPuts( session, entityEntry )
-			);
 
-			if ( put && factory.getStatistics().isStatisticsEnabled() ) {
-				factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
+			// explicit handling of caching for rows just inserted and then somehow forced to be read
+			// from the database.  usually this is done by
+			// 		1) Session#refresh, or
+			// 		2) Session#clear + some form of load
+			if ( session.wasInsertedDuringTransaction( persister, id ) ) {
+				persister.getCacheAccessStrategy().update(
+						cacheKey,
+						persister.getCacheEntryStructure().structure( entry ),
+						version,
+						version
+				);
 			}
+			else {
+				boolean put = persister.getCacheAccessStrategy().putFromLoad(
+						cacheKey,
+						persister.getCacheEntryStructure().structure( entry ),
+						session.getTimestamp(),
+						version,
+						useMinimalPuts( session, entityEntry )
+				);
+
+				if ( put && factory.getStatistics().isStatisticsEnabled() ) {
+					factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
+				}
+			}
 		}
 
 		boolean isReallyReadOnly = readOnly;

Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/SessionImpl.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/SessionImpl.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -32,6 +32,7 @@
 import java.io.ByteArrayInputStream;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -590,6 +591,7 @@
 
 	public void afterTransactionCompletion(boolean success, Transaction tx) {
 		log.trace( "after transaction completion" );
+		cleanUpInsertedKeysAfterTransaction();
 		persistenceContext.afterTransactionCompletion();
 		actionQueue.afterTransactionCompletion(success);
 		if ( rootSession == null && tx != null ) {
@@ -2006,6 +2008,50 @@
 		return loadQueryInfluencers;
 	}
 
+	private HashMap insertedKeysMap;
+
+	/**
+	 * {@inheritDoc}
+	 */
+	public void registerInsertedKey(EntityPersister persister, Serializable id) {
+		// we only are about regsitering 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();
+		}
+	}
+
+
 	// filter support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 	/**

Modified: core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -660,6 +660,17 @@
 		return LoadQueryInfluencers.NONE;
 	}
 
+	public void registerInsertedKey(EntityPersister persister, Serializable id) {
+		errorIfClosed();
+		// nothing to do
+	}
+
+	public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
+		errorIfClosed();
+		// not in any meaning we need to worry about here.
+		return false;
+	}
+
 	public void setFetchProfile(String name) {}
 
 	public void afterTransactionBegin(Transaction tx) {}

Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -77,6 +77,14 @@
 		return delegate.getLoadQueryInfluencers();
 	}
 
+	public void registerInsertedKey(EntityPersister persister, Serializable id) {
+		delegate.registerInsertedKey( persister, id );
+	}
+
+	public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) {
+		return delegate.wasInsertedDuringTransaction( persister, id );
+	}
+
 	public Interceptor getInterceptor() {
         return delegate.getInterceptor();
     }

Copied: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml (from rev 20640, core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/bytecode/Bean.hbm.xml)
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.hbm.xml	2010-09-16 20:22:17 UTC (rev 20654)
@@ -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_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -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_5/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java	                        (rev 0)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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().getCache().evictEntityRegions();
+		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_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,3 +1,26 @@
+/*
+ * 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.propertyref.component.complete;
 
 

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,3 +1,26 @@
+/*
+ * 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.propertyref.component.complete;
 
 import junit.framework.Test;
@@ -26,6 +49,8 @@
 	}
 
 	public void testComponentPropertyRef() {
+		Session s = openSession();
+		s.beginTransaction();
 		Person p = new Person();
 		p.setIdentity( new Identity() );
 		Account a = new Account();
@@ -33,13 +58,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 +90,7 @@
 
 		s.delete( a );
 		s.delete( a.getOwner() );
-		tx.commit();
+		s.getTransaction().commit();
 		s.close();
 	}
 }

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,3 +1,26 @@
+/*
+ * 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.propertyref.component.complete;
 
 import java.io.Serializable;

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,3 +1,26 @@
+/*
+ * 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.propertyref.component.complete;
 
 

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,4 +1,26 @@
-//$Id: Account.java 7587 2005-07-21 01:22:38Z oneovthafew $
+/*
+ * 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.propertyref.component.partial;
 
 public class Account {

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,4 +1,26 @@
-//$Id: Identity.java 7587 2005-07-21 01:22:38Z oneovthafew $
+/*
+ * 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.propertyref.component.partial;
 
 public class Identity {

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,4 +1,26 @@
-//$Id: PartialComponentPropertyRefTest.java 9914 2006-05-09 09:37:18Z max.andersen at jboss.com $
+/*
+ * 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.propertyref.component.partial;
 
 import junit.framework.Test;
@@ -27,6 +49,8 @@
 	}
 	
 	public void testComponentPropertyRef() {
+		Session s = openSession();
+		s.beginTransaction();
 		Person p = new Person();
 		p.setIdentity( new Identity() );
 		Account a = new Account();
@@ -34,13 +58,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 +90,7 @@
 		
 		s.delete( a );
 		s.delete( a.getOwner() );
-		tx.commit();
+		s.getTransaction().commit();
 		s.close();
 	}
 }

Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java	2010-09-16 17:26:33 UTC (rev 20653)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java	2010-09-16 20:22:17 UTC (rev 20654)
@@ -1,4 +1,26 @@
-//$Id: Person.java 7587 2005-07-21 01:22:38Z oneovthafew $
+/*
+ * 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.propertyref.component.partial;
 
 public class Person {



More information about the hibernate-commits mailing list