Merge branch 'master' into wip/6.0_merge_41
This commit is contained in:
commit
57ebf48b45
|
@ -1 +1 @@
|
|||
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError
|
||||
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en
|
|
@ -523,6 +523,7 @@ public class ModelBinder {
|
|||
PersistentClass superEntityDescriptor) {
|
||||
for ( IdentifiableTypeSource subType : entitySource.getSubTypes() ) {
|
||||
final SingleTableSubclass subEntityDescriptor = new SingleTableSubclass( superEntityDescriptor, metadataBuildingContext );
|
||||
subEntityDescriptor.setCached( superEntityDescriptor.isCached() );
|
||||
bindDiscriminatorSubclassEntity( (SubclassEntitySourceImpl) subType, subEntityDescriptor );
|
||||
superEntityDescriptor.addSubclass( subEntityDescriptor );
|
||||
entitySource.getLocalMetadataBuildingContext().getMetadataCollector().addEntityBinding( subEntityDescriptor );
|
||||
|
@ -581,6 +582,7 @@ public class ModelBinder {
|
|||
PersistentClass superEntityDescriptor) {
|
||||
for ( IdentifiableTypeSource subType : entitySource.getSubTypes() ) {
|
||||
final JoinedSubclass subEntityDescriptor = new JoinedSubclass( superEntityDescriptor, metadataBuildingContext );
|
||||
subEntityDescriptor.setCached( superEntityDescriptor.isCached() );
|
||||
bindJoinedSubclassEntity( (JoinedSubclassEntitySourceImpl) subType, subEntityDescriptor );
|
||||
superEntityDescriptor.addSubclass( subEntityDescriptor );
|
||||
entitySource.getLocalMetadataBuildingContext().getMetadataCollector().addEntityBinding( subEntityDescriptor );
|
||||
|
@ -657,6 +659,7 @@ public class ModelBinder {
|
|||
PersistentClass superEntityDescriptor) {
|
||||
for ( IdentifiableTypeSource subType : entitySource.getSubTypes() ) {
|
||||
final UnionSubclass subEntityDescriptor = new UnionSubclass( superEntityDescriptor, metadataBuildingContext );
|
||||
subEntityDescriptor.setCached( superEntityDescriptor.isCached() );
|
||||
bindUnionSubclassEntity( (SubclassEntitySourceImpl) subType, subEntityDescriptor );
|
||||
superEntityDescriptor.addSubclass( subEntityDescriptor );
|
||||
entitySource.getLocalMetadataBuildingContext().getMetadataCollector().addEntityBinding( subEntityDescriptor );
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
|
@ -985,6 +986,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
@Override
|
||||
public void initializeNonLazyCollections() throws HibernateException {
|
||||
initializeNonLazyCollections( PersistentCollection::forceInitialization );
|
||||
}
|
||||
|
||||
protected void initializeNonLazyCollections(Consumer<PersistentCollection> initializeAction ) {
|
||||
if ( loadCounter == 0 ) {
|
||||
LOG.trace( "Initializing non-lazy collections" );
|
||||
|
||||
|
@ -995,7 +1000,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
int size;
|
||||
while ( nonlazyCollections != null && ( size = nonlazyCollections.size() ) > 0 ) {
|
||||
//note that each iteration of the loop may add new elements
|
||||
nonlazyCollections.remove( size - 1 ).forceInitialization();
|
||||
initializeAction.accept( nonlazyCollections.remove( size - 1 ) );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.hibernate.event.spi.PostLoadEventListener;
|
|||
import org.hibernate.event.spi.PreLoadEvent;
|
||||
import org.hibernate.event.spi.PreLoadEventListener;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
|
||||
|
@ -419,6 +420,20 @@ public final class TwoPhaseLoad {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be removed.
|
||||
* @deprecated Use {@link #postLoad(Object, SharedSessionContractImplementor, PostLoadEvent)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void postLoad(
|
||||
final Object entity,
|
||||
final SharedSessionContractImplementor session,
|
||||
final PostLoadEvent postLoadEvent,
|
||||
final Iterable<PostLoadEventListener> postLoadEventListeners) {
|
||||
postLoad( entity, session, postLoadEvent );
|
||||
}
|
||||
|
||||
/**
|
||||
* PostLoad cannot occur during initializeEntity, as that call occurs *before*
|
||||
* the Set collections are added to the persistence context by Loader.
|
||||
|
@ -431,42 +446,17 @@ public final class TwoPhaseLoad {
|
|||
* @param session The Session
|
||||
* @param postLoadEvent The (re-used) post-load event
|
||||
*/
|
||||
public static void postLoad(
|
||||
final Object entity,
|
||||
final SharedSessionContractImplementor session,
|
||||
final PostLoadEvent postLoadEvent,
|
||||
final Iterable<PostLoadEventListener> postLoadEventListeners) {
|
||||
|
||||
if ( session.isEventSource() ) {
|
||||
final PersistenceContext persistenceContext
|
||||
= session.getPersistenceContextInternal();
|
||||
final EntityEntry entityEntry = persistenceContext.getEntry( entity );
|
||||
|
||||
postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );
|
||||
|
||||
for ( PostLoadEventListener listener : postLoadEventListeners ) {
|
||||
listener.onPostLoad( postLoadEvent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be removed.
|
||||
* @deprecated Use {@link #postLoad(Object, SharedSessionContractImplementor, PostLoadEvent, Iterable)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static void postLoad(
|
||||
final Object entity,
|
||||
final SharedSessionContractImplementor session,
|
||||
final PostLoadEvent postLoadEvent) {
|
||||
if ( session.isEventSource() ) {
|
||||
final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( entity );
|
||||
|
||||
final EventListenerGroup<PostLoadEventListener> listenerGroup = session.getFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( EventListenerRegistry.class )
|
||||
.getEventListenerGroup( EventType.POST_LOAD );
|
||||
postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() );
|
||||
|
||||
postLoad( entity, session, postLoadEvent, listenerGroup.listeners() );
|
||||
session.getFactory().getFastSessionServices().firePostLoadEvent( postLoadEvent );
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean useMinimalPuts(SharedSessionContractImplementor session, EntityEntry entityEntry) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.hibernate.exception.spi.SQLExceptionConverter;
|
|||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.metadata.ClassMetadata;
|
||||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.RuntimeMetamodels;
|
||||
|
@ -329,6 +330,11 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
|
|||
return delegate.iterateEntityNameResolvers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FastSessionServices getFastSessionServices() {
|
||||
return delegate.getFastSessionServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPersister locateEntityPersister(Class byClass) {
|
||||
return delegate.locateEntityPersister( byClass );
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.hibernate.graph.spi.RootGraphImplementor;
|
|||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.RuntimeMetamodels;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.metamodel.spi.MetamodelImplementor;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
@ -155,6 +156,11 @@ public interface SessionFactoryImplementor
|
|||
return getMetamodel().getEntityNameResolvers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the FastSessionServices instance associated with this SessionFactory
|
||||
*/
|
||||
FastSessionServices getFastSessionServices();
|
||||
|
||||
/**
|
||||
* Contract for resolving this SessionFactory on deserialization
|
||||
*/
|
||||
|
|
|
@ -39,6 +39,8 @@ import org.hibernate.event.spi.LoadEventListener;
|
|||
import org.hibernate.event.spi.LockEventListener;
|
||||
import org.hibernate.event.spi.MergeEventListener;
|
||||
import org.hibernate.event.spi.PersistEventListener;
|
||||
import org.hibernate.event.spi.PostLoadEvent;
|
||||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.event.spi.RefreshEventListener;
|
||||
import org.hibernate.event.spi.ReplicateEventListener;
|
||||
import org.hibernate.event.spi.ResolveNaturalIdEventListener;
|
||||
|
@ -77,7 +79,7 @@ import static org.hibernate.cfg.AvailableSettings.JPA_SHARED_CACHE_STORE_MODE;
|
|||
*
|
||||
* @author Sanne Grinovero
|
||||
*/
|
||||
final class FastSessionServices {
|
||||
public final class FastSessionServices {
|
||||
|
||||
/**
|
||||
* Default session properties
|
||||
|
@ -104,6 +106,9 @@ final class FastSessionServices {
|
|||
final EventListenerGroup<SaveOrUpdateEventListener> eventListenerGroup_SAVE_UPDATE;
|
||||
final EventListenerGroup<SaveOrUpdateEventListener> eventListenerGroup_UPDATE;
|
||||
|
||||
//Frequently used by 2LC initialization:
|
||||
final EventListenerGroup<PostLoadEventListener> eventListenerGroup_POST_LOAD;
|
||||
|
||||
//Intentionally Package private:
|
||||
final boolean disallowOutOfTransactionUpdateOperations;
|
||||
final boolean useStreamForLobBinding;
|
||||
|
@ -152,6 +157,7 @@ final class FastSessionServices {
|
|||
this.eventListenerGroup_SAVE = listeners( eventListenerRegistry, EventType.SAVE );
|
||||
this.eventListenerGroup_SAVE_UPDATE = listeners( eventListenerRegistry, EventType.SAVE_UPDATE );
|
||||
this.eventListenerGroup_UPDATE = listeners( eventListenerRegistry, EventType.UPDATE );
|
||||
this.eventListenerGroup_POST_LOAD = listeners( eventListenerRegistry, EventType.POST_LOAD );
|
||||
|
||||
//Other highly useful constants:
|
||||
this.dialect = jdbcServices.getJdbcEnvironment().getDialect();
|
||||
|
@ -282,4 +288,7 @@ final class FastSessionServices {
|
|||
return defaultJdbcObservers;
|
||||
}
|
||||
|
||||
public void firePostLoadEvent(final PostLoadEvent postLoadEvent) {
|
||||
eventListenerGroup_POST_LOAD.fireEventOnEachListener( postLoadEvent, PostLoadEventListener::onPostLoad );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1616,7 +1616,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
|||
/**
|
||||
* @return the FastSessionServices for this SessionFactory.
|
||||
*/
|
||||
FastSessionServices getFastSessionServices() {
|
||||
@Override
|
||||
public FastSessionServices getFastSessionServices() {
|
||||
return this.fastSessionServices;
|
||||
}
|
||||
|
||||
|
|
|
@ -189,8 +189,8 @@ public class SessionImpl
|
|||
public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
|
||||
super( factory, options );
|
||||
|
||||
this.actionQueue = new ActionQueue( this );
|
||||
this.persistenceContext = new StatefulPersistenceContext( this );
|
||||
this.persistenceContext = createPersistenceContext();
|
||||
this.actionQueue = createActionQueue();
|
||||
|
||||
this.autoClear = options.shouldAutoClear();
|
||||
this.autoClose = options.shouldAutoClose();
|
||||
|
@ -237,6 +237,14 @@ public class SessionImpl
|
|||
}
|
||||
}
|
||||
|
||||
protected StatefulPersistenceContext createPersistenceContext() {
|
||||
return new StatefulPersistenceContext( this );
|
||||
}
|
||||
|
||||
protected ActionQueue createActionQueue() {
|
||||
return new ActionQueue( this );
|
||||
}
|
||||
|
||||
private LockOptions getLockOptionsForRead() {
|
||||
return this.lockOptions == null ? fastSessionServices.defaultLockOptions : this.lockOptions;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.hibernate.event.spi.PostLoadEvent;
|
|||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.FastSessionServices;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
@ -356,22 +357,13 @@ public class CacheEntityLoaderHelper extends AbstractLockUpgradeEventListener {
|
|||
.setId( entityId )
|
||||
.setPersister( persister );
|
||||
|
||||
for ( PostLoadEventListener listener : postLoadEventListeners( session ) ) {
|
||||
listener.onPostLoad( postLoadEvent );
|
||||
}
|
||||
session.getSessionFactory()
|
||||
.getFastSessionServices()
|
||||
.firePostLoadEvent( postLoadEvent );
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
private Iterable<PostLoadEventListener> postLoadEventListeners(EventSource session) {
|
||||
return session
|
||||
.getFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( EventListenerRegistry.class )
|
||||
.getEventListenerGroup( EventType.POST_LOAD )
|
||||
.listeners();
|
||||
}
|
||||
|
||||
public static class PersistenceContextEntry {
|
||||
private final Object entity;
|
||||
private EntityStatus status;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public class DiscriminatorSubclassNonUIPerson extends DiscriminatorSubclassPerson {
|
||||
}
|
20
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/DiscriminatorSubclassPerson.java
vendored
Normal file
20
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/DiscriminatorSubclassPerson.java
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public abstract class DiscriminatorSubclassPerson {
|
||||
|
||||
private Long oid;
|
||||
|
||||
public Long getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public void setOid(Long oid) {
|
||||
this.oid = oid;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public class DiscriminatorSubclassUIPerson extends DiscriminatorSubclassPerson {
|
||||
}
|
169
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/HHH13179Test.java
vendored
Normal file
169
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/HHH13179Test.java
vendored
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.stat.CacheRegionStatistics;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Check that second level caching works for hbm mapped joined subclass inheritance structures
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-13179")
|
||||
public class HHH13179Test extends BaseCoreFunctionalTestCase {
|
||||
|
||||
// Add your entities here.
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
JoinedSubclassPerson.class,
|
||||
JoinedSubclassUIPerson.class,
|
||||
JoinedSubclassNonUIPerson.class,
|
||||
UnionSubclassPerson.class,
|
||||
UnionSubclassUIPerson.class,
|
||||
UnionSubclassNonUIPerson.class,
|
||||
DiscriminatorSubclassPerson.class,
|
||||
DiscriminatorSubclassUIPerson.class,
|
||||
DiscriminatorSubclassNonUIPerson.class
|
||||
};
|
||||
}
|
||||
|
||||
// If you use *.hbm.xml mappings, instead of annotations, add the mappings here.
|
||||
@Override
|
||||
protected String[] getMappings() {
|
||||
return new String[] {
|
||||
"org/hibernate/test/cache/hhh13179/JoinedSubclassPerson.hbm.xml",
|
||||
"org/hibernate/test/cache/hhh13179/UnionSubclassPerson.hbm.xml",
|
||||
"org/hibernate/test/cache/hhh13179/DiscriminatorSubclassPerson.hbm.xml"
|
||||
};
|
||||
}
|
||||
|
||||
// If those mappings reside somewhere other than resources/org/hibernate/test, change this.
|
||||
@Override
|
||||
protected String getBaseForMappings() {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Add in any settings that are specific to your test. See resources/hibernate.properties for the defaults.
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
super.configure( configuration );
|
||||
|
||||
configuration.setProperty( AvailableSettings.SHOW_SQL, Boolean.TRUE.toString() );
|
||||
configuration.setProperty( AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString() );
|
||||
configuration.setProperty( AvailableSettings.GENERATE_STATISTICS, "true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinedSubclassCaching() {
|
||||
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
String regionName = "org.hibernate.test.cache.hhh13179.JoinedSubclassPerson";
|
||||
|
||||
// sanity check
|
||||
CacheRegionStatistics cacheRegionStatistics = s.getSessionFactory().getStatistics().getCacheRegionStatistics(
|
||||
regionName );
|
||||
Assert.assertEquals( "Cache put should be 0", 0, cacheRegionStatistics.getPutCount() );
|
||||
|
||||
JoinedSubclassPerson person1 = new JoinedSubclassUIPerson();
|
||||
person1.setOid( 1L );
|
||||
s.save( person1 );
|
||||
|
||||
tx.commit();
|
||||
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
|
||||
JoinedSubclassPerson person2 = s.get( JoinedSubclassPerson.class, 1L );
|
||||
|
||||
cacheRegionStatistics = s.getSessionFactory().getStatistics().getCacheRegionStatistics( regionName );
|
||||
Assert.assertEquals( "Cache hit should be 1", 1, cacheRegionStatistics.getHitCount() );
|
||||
Assert.assertEquals( "Cache put should be 1", 1, cacheRegionStatistics.getPutCount() );
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionSubclassCaching() {
|
||||
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
String regionName = "org.hibernate.test.cache.hhh13179.UnionSubclassPerson";
|
||||
|
||||
// sanity check
|
||||
CacheRegionStatistics cacheRegionStatistics = s.getSessionFactory().getStatistics().getCacheRegionStatistics(
|
||||
regionName );
|
||||
Assert.assertEquals( "Cache put should be 0", 0, cacheRegionStatistics.getPutCount() );
|
||||
|
||||
UnionSubclassPerson person1 = new UnionSubclassUIPerson();
|
||||
person1.setOid( 1L );
|
||||
s.save( person1 );
|
||||
|
||||
tx.commit();
|
||||
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
|
||||
UnionSubclassPerson person2 = s.get( UnionSubclassPerson.class, 1L );
|
||||
|
||||
cacheRegionStatistics = s.getSessionFactory().getStatistics().getCacheRegionStatistics( regionName );
|
||||
Assert.assertEquals( "Cache hit should be 1", 1, cacheRegionStatistics.getHitCount() );
|
||||
Assert.assertEquals( "Cache put should be 1", 1, cacheRegionStatistics.getPutCount() );
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDiscriminatorSubclassCaching() {
|
||||
// BaseCoreFunctionalTestCase automatically creates the SessionFactory and provides the Session.
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
String regionName = "org.hibernate.test.cache.hhh13179.DiscriminatorSubclassPerson";
|
||||
|
||||
// sanity check
|
||||
CacheRegionStatistics cacheRegionStatistics = s.getSessionFactory().getStatistics().getCacheRegionStatistics(
|
||||
regionName );
|
||||
Assert.assertEquals( "Cache put should be 0", 0, cacheRegionStatistics.getPutCount() );
|
||||
|
||||
DiscriminatorSubclassPerson person1 = new DiscriminatorSubclassUIPerson();
|
||||
person1.setOid( 1L );
|
||||
s.save( person1 );
|
||||
|
||||
tx.commit();
|
||||
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
|
||||
DiscriminatorSubclassPerson person2 = s.get( DiscriminatorSubclassPerson.class, 1L );
|
||||
|
||||
cacheRegionStatistics = s.getSessionFactory().getStatistics().getCacheRegionStatistics( regionName );
|
||||
Assert.assertEquals( "Cache hit should be 1", 1, cacheRegionStatistics.getHitCount() );
|
||||
Assert.assertEquals( "Cache put should be 1", 1, cacheRegionStatistics.getPutCount() );
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/JoinedSubclassNonUIPerson.java
vendored
Normal file
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/JoinedSubclassNonUIPerson.java
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public class JoinedSubclassNonUIPerson extends JoinedSubclassPerson {
|
||||
}
|
20
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/JoinedSubclassPerson.java
vendored
Normal file
20
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/JoinedSubclassPerson.java
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public abstract class JoinedSubclassPerson {
|
||||
|
||||
private Long oid;
|
||||
|
||||
public Long getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public void setOid(Long oid) {
|
||||
this.oid = oid;
|
||||
}
|
||||
}
|
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/JoinedSubclassUIPerson.java
vendored
Normal file
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/JoinedSubclassUIPerson.java
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public class JoinedSubclassUIPerson extends JoinedSubclassPerson {
|
||||
}
|
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/UnionSubclassNonUIPerson.java
vendored
Normal file
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/UnionSubclassNonUIPerson.java
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public class UnionSubclassNonUIPerson extends UnionSubclassPerson {
|
||||
}
|
20
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/UnionSubclassPerson.java
vendored
Normal file
20
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/UnionSubclassPerson.java
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public abstract class UnionSubclassPerson {
|
||||
|
||||
private Long oid;
|
||||
|
||||
public Long getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
public void setOid(Long oid) {
|
||||
this.oid = oid;
|
||||
}
|
||||
}
|
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/UnionSubclassUIPerson.java
vendored
Normal file
10
hibernate-core/src/test/java/org/hibernate/test/cache/hhh13179/UnionSubclassUIPerson.java
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.cache.hhh13179;
|
||||
|
||||
public class UnionSubclassUIPerson extends UnionSubclassPerson {
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping default-lazy="false">
|
||||
<class name="org.hibernate.test.cache.hhh13179.DiscriminatorSubclassPerson" table="DISCRIMINATOR_SUBCLASS_PERSON">
|
||||
<cache usage="read-write"/>
|
||||
|
||||
<id name="oid" column="PERSON_ID" type="long" unsaved-value="null">
|
||||
<generator class="org.hibernate.id.Assigned"/>
|
||||
</id>
|
||||
|
||||
<discriminator column="type" type="string" />
|
||||
|
||||
<subclass name="org.hibernate.test.cache.hhh13179.DiscriminatorSubclassUIPerson" discriminator-value="UI_PERSON">
|
||||
</subclass>
|
||||
|
||||
<subclass name="org.hibernate.test.cache.hhh13179.DiscriminatorSubclassNonUIPerson" discriminator-value="NON_UI_PERSON">
|
||||
</subclass>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
30
hibernate-core/src/test/resources/org/hibernate/test/cache/hhh13179/JoinedSubclassPerson.hbm.xml
vendored
Normal file
30
hibernate-core/src/test/resources/org/hibernate/test/cache/hhh13179/JoinedSubclassPerson.hbm.xml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping default-lazy="false">
|
||||
<class name="org.hibernate.test.cache.hhh13179.JoinedSubclassPerson" table="JOINED_SUBCLASS_PERSON">
|
||||
<cache usage="read-write"/>
|
||||
|
||||
<id name="oid" column="PERSON_ID" type="long" unsaved-value="null">
|
||||
<generator class="org.hibernate.id.Assigned"/>
|
||||
</id>
|
||||
|
||||
<joined-subclass name="org.hibernate.test.cache.hhh13179.JoinedSubclassUIPerson" table="JOINED_SUBCLASS_UI_PERSON">
|
||||
<key column="PERSON_ID"/>
|
||||
</joined-subclass>
|
||||
|
||||
|
||||
<joined-subclass name="org.hibernate.test.cache.hhh13179.JoinedSubclassNonUIPerson" table="JOINED_SUBCLASS_NON_UI_PERSON">
|
||||
<key column="PERSON_ID"/>
|
||||
</joined-subclass>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
27
hibernate-core/src/test/resources/org/hibernate/test/cache/hhh13179/UnionSubclassPerson.hbm.xml
vendored
Normal file
27
hibernate-core/src/test/resources/org/hibernate/test/cache/hhh13179/UnionSubclassPerson.hbm.xml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--
|
||||
~ Hibernate, Relational Persistence for Idiomatic Java
|
||||
~
|
||||
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping default-lazy="false">
|
||||
<class name="org.hibernate.test.cache.hhh13179.UnionSubclassPerson" table="UNION_SUBCLASS_PERSON">
|
||||
<cache usage="read-write"/>
|
||||
|
||||
<id name="oid" column="PERSON_ID" type="long" unsaved-value="null">
|
||||
<generator class="org.hibernate.id.Assigned"/>
|
||||
</id>
|
||||
|
||||
<union-subclass name="org.hibernate.test.cache.hhh13179.UnionSubclassUIPerson" table="UNION_SUBCLASS_UI_PERSON">
|
||||
</union-subclass>
|
||||
|
||||
<union-subclass name="org.hibernate.test.cache.hhh13179.UnionSubclassNonUIPerson" table="UNION_SUBCLASS_NON_UI_PERSON">
|
||||
</union-subclass>
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
Loading…
Reference in New Issue