[hibernate-commits] Hibernate SVN: r20655 - in core/trunk: 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:23:08 EDT 2010


Author: steve.ebersole at jboss.com
Date: 2010-09-16 16:23:07 -0400 (Thu, 16 Sep 2010)
New Revision: 20655

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


Modified: core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/core/src/main/java/org/hibernate/action/EntityIdentityInsertAction.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/core/src/main/java/org/hibernate/action/EntityInsertAction.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -92,7 +92,8 @@
 				}
 				entry.postUpdate(instance, state, version);
 			}
-			
+
+			getSession().registerInsertedKey( getPersister(), getId() );
 		}
 
 		final SessionFactoryImplementor factory = getSession().getFactory();

Modified: core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/core/src/main/java/org/hibernate/engine/SessionImplementor.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/core/src/main/java/org/hibernate/engine/TwoPhaseLoad.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -176,17 +176,34 @@
 					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 *within the same transaction*.  usually this is done by
+			// 		1) Session#refresh, or
+			// 		2) Session#clear + some form of load
+			//
+			// we need to be careful not to clobber the lock here in the cache so that it can be rolled back if need be
+			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/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionImpl.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -36,6 +36,7 @@
 import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -597,6 +598,7 @@
 
 	public void afterTransactionCompletion(boolean success, Transaction tx) {
 		log.trace( "after transaction completion" );
+		cleanUpInsertedKeysAfterTransaction();
 		persistenceContext.afterTransactionCompletion();
 		actionQueue.afterTransactionCompletion(success);
 		if ( rootSession == null && tx != null ) {
@@ -2015,6 +2017,49 @@
 		return loadQueryInfluencers;
 	}
 
+	private HashMap<String,List<Serializable>> 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<String, List<Serializable>>();
+			}
+			final String rootEntityName = persister.getRootEntityName();
+			List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName );
+			if ( insertedEntityIds == null ) {
+				insertedEntityIds = new ArrayList<Serializable>();
+				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<Serializable> insertedEntityIds = 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/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/core/src/main/java/org/hibernate/impl/StatelessSessionImpl.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/AbstractDelegateSessionImplementor.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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();
     }

Added: core/trunk/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java	                        (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/cache/CacheableItem.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -0,0 +1,71 @@
+/*
+ * 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 javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.CacheConcurrencyStrategy;
+import org.hibernate.annotations.GenericGenerator;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+ at Entity
+ at Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "item")
+public class CacheableItem {
+	private Long id;
+	private String name;
+
+	public CacheableItem() {
+	}
+
+	public CacheableItem(String name) {
+		this.name = name;
+	}
+
+	@Id
+	@GeneratedValue(generator = "increment")
+	@GenericGenerator(name = "increment", strategy = "increment")
+	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/trunk/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java	                        (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/cache/InsertedDataTest.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -0,0 +1,232 @@
+/*
+ * 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.test.annotations.TestCase;
+
+/**
+ * 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 TestCase {
+	@Override
+	protected Class<?>[] getAnnotatedClasses() {
+		return new Class[] { CacheableItem.class };
+	}
+
+	@Override
+	protected 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( "item" ).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( "item" ).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( "item" ).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( "item" ).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( "item" ).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( "item" ).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( "item" ).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( "item" ).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/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Account.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/CompleteComponentPropertyRefTest.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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;
@@ -4,7 +27,6 @@
 
 import org.hibernate.Hibernate;
 import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.hibernate.testing.junit.functional.FunctionalTestCase;
 import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
 
@@ -26,6 +48,8 @@
 	}
 
 	public void testComponentPropertyRef() {
+		Session s = openSession();
+		s.beginTransaction();
 		Person p = new Person();
 		p.setIdentity( new Identity() );
 		Account a = new Account();
@@ -33,13 +57,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 +89,7 @@
 
 		s.delete( a );
 		s.delete( a.getOwner() );
-		tx.commit();
+		s.getTransaction().commit();
 		s.close();
 	}
 }

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Identity.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/complete/Person.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Account.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Identity.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/PartialComponentPropertyRefTest.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -1,11 +1,32 @@
-//$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;
 
 import org.hibernate.Hibernate;
 import org.hibernate.Session;
-import org.hibernate.Transaction;
 import org.hibernate.testing.junit.functional.FunctionalTestCase;
 import org.hibernate.testing.junit.functional.FunctionalTestClassTestSuite;
 
@@ -27,6 +48,8 @@
 	}
 	
 	public void testComponentPropertyRef() {
+		Session s = openSession();
+		s.beginTransaction();
 		Person p = new Person();
 		p.setIdentity( new Identity() );
 		Account a = new Account();
@@ -34,13 +57,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 +89,7 @@
 		
 		s.delete( a );
 		s.delete( a.getOwner() );
-		tx.commit();
+		s.getTransaction().commit();
 		s.close();
 	}
 }

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java	2010-09-16 20:22:17 UTC (rev 20654)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/propertyref/component/partial/Person.java	2010-09-16 20:23:07 UTC (rev 20655)
@@ -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