HHH-5490 - dirty data be inserted into 2L cache
git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_5@20654 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
560e7ff1d7
commit
da27e3545e
|
@ -75,6 +75,7 @@ public final class EntityIdentityInsertAction extends EntityAction {
|
||||||
//need to do that here rather than in the save event listener to let
|
//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)
|
//the post insert events to have a id-filled entity when IDENTITY is used (EJB3)
|
||||||
persister.setIdentifier( instance, generatedId, session );
|
persister.setIdentifier( instance, generatedId, session );
|
||||||
|
getSession().registerInsertedKey( getPersister(), generatedId );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class EntityInsertAction extends EntityAction {
|
||||||
}
|
}
|
||||||
entry.postUpdate(instance, state, version);
|
entry.postUpdate(instance, state, version);
|
||||||
}
|
}
|
||||||
|
getSession().registerInsertedKey( getPersister(), getId() );
|
||||||
}
|
}
|
||||||
|
|
||||||
final SessionFactoryImplementor factory = getSession().getFactory();
|
final SessionFactoryImplementor factory = getSession().getFactory();
|
||||||
|
|
|
@ -365,4 +365,22 @@ public interface SessionImplementor extends Serializable {
|
||||||
* should never be null.
|
* should never be null.
|
||||||
*/
|
*/
|
||||||
public LoadQueryInfluencers getLoadQueryInfluencers();
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
|
import org.hibernate.cache.access.SoftLock;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
import org.hibernate.cache.CacheKey;
|
import org.hibernate.cache.CacheKey;
|
||||||
import org.hibernate.cache.entry.CacheEntry;
|
import org.hibernate.cache.entry.CacheEntry;
|
||||||
|
@ -177,16 +178,31 @@ public final class TwoPhaseLoad {
|
||||||
session.getEntityMode(),
|
session.getEntityMode(),
|
||||||
session.getFactory()
|
session.getFactory()
|
||||||
);
|
);
|
||||||
boolean put = persister.getCacheAccessStrategy().putFromLoad(
|
|
||||||
cacheKey,
|
|
||||||
persister.getCacheEntryStructure().structure( entry ),
|
|
||||||
session.getTimestamp(),
|
|
||||||
version,
|
|
||||||
useMinimalPuts( session, entityEntry )
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
|
// explicit handling of caching for rows just inserted and then somehow forced to be read
|
||||||
factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
|
// 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() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -590,6 +591,7 @@ public final class SessionImpl extends AbstractSessionImpl
|
||||||
|
|
||||||
public void afterTransactionCompletion(boolean success, Transaction tx) {
|
public void afterTransactionCompletion(boolean success, Transaction tx) {
|
||||||
log.trace( "after transaction completion" );
|
log.trace( "after transaction completion" );
|
||||||
|
cleanUpInsertedKeysAfterTransaction();
|
||||||
persistenceContext.afterTransactionCompletion();
|
persistenceContext.afterTransactionCompletion();
|
||||||
actionQueue.afterTransactionCompletion(success);
|
actionQueue.afterTransactionCompletion(success);
|
||||||
if ( rootSession == null && tx != null ) {
|
if ( rootSession == null && tx != null ) {
|
||||||
|
@ -2006,6 +2008,50 @@ public final class SessionImpl extends AbstractSessionImpl
|
||||||
return loadQueryInfluencers;
|
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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// filter support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -660,6 +660,17 @@ public class StatelessSessionImpl extends AbstractSessionImpl
|
||||||
return LoadQueryInfluencers.NONE;
|
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 setFetchProfile(String name) {}
|
||||||
|
|
||||||
public void afterTransactionBegin(Transaction tx) {}
|
public void afterTransactionBegin(Transaction tx) {}
|
||||||
|
|
|
@ -77,6 +77,14 @@ public abstract class AbstractDelegateSessionImplementor implements SessionImple
|
||||||
return delegate.getLoadQueryInfluencers();
|
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() {
|
public Interceptor getInterceptor() {
|
||||||
return delegate.getInterceptor();
|
return delegate.getInterceptor();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.complete;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.complete;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
@ -26,6 +49,8 @@ public class CompleteComponentPropertyRefTest extends FunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testComponentPropertyRef() {
|
public void testComponentPropertyRef() {
|
||||||
|
Session s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
Person p = new Person();
|
Person p = new Person();
|
||||||
p.setIdentity( new Identity() );
|
p.setIdentity( new Identity() );
|
||||||
Account a = new Account();
|
Account a = new Account();
|
||||||
|
@ -33,13 +58,13 @@ public class CompleteComponentPropertyRefTest extends FunctionalTestCase {
|
||||||
a.setOwner(p);
|
a.setOwner(p);
|
||||||
p.getIdentity().setName("Gavin");
|
p.getIdentity().setName("Gavin");
|
||||||
p.getIdentity().setSsn("123-12-1234");
|
p.getIdentity().setSsn("123-12-1234");
|
||||||
Session s = openSession();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
s.persist(p);
|
s.persist(p);
|
||||||
s.persist(a);
|
s.persist(a);
|
||||||
s.flush();
|
s.getTransaction().commit();
|
||||||
s.clear();
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
|
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
|
||||||
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
|
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
|
||||||
assertNotNull( a.getOwner() );
|
assertNotNull( a.getOwner() );
|
||||||
|
@ -65,7 +90,7 @@ public class CompleteComponentPropertyRefTest extends FunctionalTestCase {
|
||||||
|
|
||||||
s.delete( a );
|
s.delete( a );
|
||||||
s.delete( a.getOwner() );
|
s.delete( a.getOwner() );
|
||||||
tx.commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.complete;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.complete;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.partial;
|
||||||
|
|
||||||
public class Account {
|
public class Account {
|
||||||
|
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.partial;
|
||||||
|
|
||||||
public class Identity {
|
public class Identity {
|
||||||
|
|
|
@ -1,4 +1,26 @@
|
||||||
//$Id: PartialComponentPropertyRefTest.java 9914 2006-05-09 09:37:18Z max.andersen@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;
|
package org.hibernate.test.propertyref.component.partial;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
|
@ -27,6 +49,8 @@ public class PartialComponentPropertyRefTest extends FunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testComponentPropertyRef() {
|
public void testComponentPropertyRef() {
|
||||||
|
Session s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
Person p = new Person();
|
Person p = new Person();
|
||||||
p.setIdentity( new Identity() );
|
p.setIdentity( new Identity() );
|
||||||
Account a = new Account();
|
Account a = new Account();
|
||||||
|
@ -34,13 +58,13 @@ public class PartialComponentPropertyRefTest extends FunctionalTestCase {
|
||||||
a.setOwner(p);
|
a.setOwner(p);
|
||||||
p.getIdentity().setName("Gavin");
|
p.getIdentity().setName("Gavin");
|
||||||
p.getIdentity().setSsn("123-12-1234");
|
p.getIdentity().setSsn("123-12-1234");
|
||||||
Session s = openSession();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
s.persist(p);
|
s.persist(p);
|
||||||
s.persist(a);
|
s.persist(a);
|
||||||
s.flush();
|
s.getTransaction().commit();
|
||||||
s.clear();
|
s.close();
|
||||||
|
|
||||||
|
s = openSession();
|
||||||
|
s.beginTransaction();
|
||||||
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
|
a = (Account) s.createQuery("from Account a left join fetch a.owner").uniqueResult();
|
||||||
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
|
assertTrue( Hibernate.isInitialized( a.getOwner() ) );
|
||||||
assertNotNull( a.getOwner() );
|
assertNotNull( a.getOwner() );
|
||||||
|
@ -66,7 +90,7 @@ public class PartialComponentPropertyRefTest extends FunctionalTestCase {
|
||||||
|
|
||||||
s.delete( a );
|
s.delete( a );
|
||||||
s.delete( a.getOwner() );
|
s.delete( a.getOwner() );
|
||||||
tx.commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
package org.hibernate.test.propertyref.component.partial;
|
||||||
|
|
||||||
public class Person {
|
public class Person {
|
||||||
|
|
Loading…
Reference in New Issue