HHH-14212 revert back HHH-8776 (retaining testing case)

This commit is contained in:
Nathan Xu 2020-09-13 09:34:59 -04:00 committed by Sanne Grinovero
parent c0a7b66273
commit ce70858df3
4 changed files with 2 additions and 114 deletions

View File

@ -32,8 +32,6 @@ import org.hibernate.event.spi.PostLoadEvent;
import org.hibernate.event.spi.PostLoadEventListener;
import org.hibernate.event.spi.PreLoadEvent;
import org.hibernate.event.spi.PreLoadEventListener;
import org.hibernate.graph.spi.AttributeNodeImplementor;
import org.hibernate.graph.spi.GraphImplementor;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
@ -207,8 +205,6 @@ public final class TwoPhaseLoad {
String[] propertyNames = persister.getPropertyNames();
final Type[] types = persister.getPropertyTypes();
final GraphImplementor<?> fetchGraphContext = session.getFetchGraphLoadContext();
for ( int i = 0; i < hydratedState.length; i++ ) {
final Object value = hydratedState[i];
if ( debugEnabled ) {
@ -257,10 +253,6 @@ public final class TwoPhaseLoad {
LOG.debugf( "Skipping <unknown> attribute : `%s`", propertyNames[i] );
}
}
if ( session.getFetchGraphLoadContext() != fetchGraphContext ) {
session.setFetchGraphLoadContext( fetchGraphContext );
}
}
}
@ -414,11 +406,7 @@ public final class TwoPhaseLoad {
}
/**
* Check if eager of the association is overridden (i.e. skipping metamodel strategy), including (order sensitive):
* <ol>
* <li>fetch graph</li>
* <li>fetch profile</li>
* </ol>
* Check if eager of the association is overridden by anything.
*
* @param session session
* @param entityName entity name
@ -436,25 +424,8 @@ public final class TwoPhaseLoad {
// Performance: check type.isCollectionType() first, as type.isAssociationType() is megamorphic
if ( associationType.isCollectionType() || associationType.isAssociationType() ) {
// check 'fetch graph' first; skip 'fetch profile' if 'fetch graph' takes effect
Boolean overridingEager = isEagerFetchGraph( session, associationName, associationType );
if ( overridingEager != null ) {
//This method is very hot, and private so let's piggy back on the fact that the caller already knows the debugging state.
if ( isDebugEnabled ) {
LOG.debugf(
"Overriding eager fetching using fetch graph. EntityName: %s, associationName: %s, eager fetching: %s",
entityName,
associationName,
overridingEager
);
}
return overridingEager;
}
// check 'fetch profile' next; skip 'metamodel' if 'fetch profile' takes effect
overridingEager = isEagerFetchProfile( session, entityName, associationName );
final Boolean overridingEager = isEagerFetchProfile( session, entityName, associationName );
if ( overridingEager != null ) {
//This method is very hot, and private so let's piggy back on the fact that the caller already knows the debugging state.
@ -493,39 +464,6 @@ public final class TwoPhaseLoad {
return null;
}
private static Boolean isEagerFetchGraph(SharedSessionContractImplementor session, String associationName, Type associationType) {
final GraphImplementor<?> context = session.getFetchGraphLoadContext();
if ( context != null ) {
// 'fetch graph' is in effect, so null should not be returned
final AttributeNodeImplementor<Object> attributeNode = context.findAttributeNode( associationName );
if ( attributeNode != null ) {
if ( associationType.isCollectionType() ) {
// to do: deal with Map's key and value
session.setFetchGraphLoadContext( null );
}
else {
// set 'fetchGraphContext' to sub-graph so graph is explored further (internal loading)
final GraphImplementor<?> subContext = attributeNode.getSubGraphMap().get( associationType.getReturnedClass() );
if ( subContext != null ) {
session.setFetchGraphLoadContext( subContext );
}
else {
session.setFetchGraphLoadContext( null );
}
}
// explicit 'fetch graph' applies, so fetch eagerly
return true;
}
else {
// implicit 'fetch graph' applies, so fetch lazily
return false;
}
}
return null;
}
/**
* This method will be removed.
* @deprecated Use {@link #postLoad(Object, SharedSessionContractImplementor, PostLoadEvent)}

View File

@ -30,7 +30,6 @@ import org.hibernate.engine.jdbc.LobCreationContext;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
import org.hibernate.graph.spi.GraphImplementor;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.spi.HibernateEntityManagerImplementor;
import org.hibernate.loader.custom.CustomQuery;
@ -523,31 +522,4 @@ public interface SharedSessionContractImplementor
*/
PersistenceContext getPersistenceContextInternal();
/**
* Get the current fetch graph context (either {@link org.hibernate.graph.spi.RootGraphImplementor} or {@link org.hibernate.graph.spi.SubGraphImplementor}.
* Suppose fetch graph is "a(b(c))", then during {@link org.hibernate.engine.internal.TwoPhaseLoad}:
* <ul>
* <li>when loading root</li>: {@link org.hibernate.graph.spi.RootGraphImplementor root} will be returned
* <li>when internally loading 'a'</li>: {@link org.hibernate.graph.spi.SubGraphImplementor subgraph} of 'a' will be returned
* <li>when internally loading 'b'</li>: {@link org.hibernate.graph.spi.SubGraphImplementor subgraph} of 'a(b)' will be returned
* <li>when internally loading 'c'</li>: {@link org.hibernate.graph.spi.SubGraphImplementor subgraph} of 'a(b(c))' will be returned
* </ul>
*
* @return current fetch graph context; can be null if fetch graph is not effective or the graph eager loading is done.
* @see #setFetchGraphLoadContext(GraphImplementor)
* @see org.hibernate.engine.internal.TwoPhaseLoad
*/
default GraphImplementor getFetchGraphLoadContext() {
return null;
}
/**
* Set the current fetch graph context (either {@link org.hibernate.graph.spi.RootGraphImplementor} or {@link org.hibernate.graph.spi.SubGraphImplementor}.
*
* @param fetchGraphLoadContext new fetch graph context; can be null (this field will be set to null after root entity loading is done).
* @see #getFetchGraphLoadContext()
*/
default void setFetchGraphLoadContext(GraphImplementor fetchGraphLoadContext) {
}
}

View File

@ -130,7 +130,6 @@ import org.hibernate.event.spi.SaveOrUpdateEventListener;
import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.RootGraph;
import org.hibernate.graph.internal.RootGraphImpl;
import org.hibernate.graph.spi.GraphImplementor;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.internal.CriteriaImpl.CriterionEntry;
@ -216,8 +215,6 @@ public class SessionImpl
private transient TransactionObserver transactionObserver;
private transient GraphImplementor fetchGraphLoadContext;
public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
super( factory, options );
@ -3316,10 +3313,6 @@ public class SessionImpl
loadAccess.with( lockOptions );
}
if ( getLoadQueryInfluencers().getEffectiveEntityGraph().getSemantic() == GraphSemantic.FETCH ) {
setFetchGraphLoadContext( getLoadQueryInfluencers().getEffectiveEntityGraph().getGraph() );
}
return loadAccess.load( (Serializable) primaryKey );
}
catch ( EntityNotFoundException ignored ) {
@ -3364,7 +3357,6 @@ public class SessionImpl
finally {
getLoadQueryInfluencers().getEffectiveEntityGraph().clear();
getLoadQueryInfluencers().setReadOnly( null );
setFetchGraphLoadContext( null );
}
}
@ -3738,16 +3730,6 @@ public class SessionImpl
return getEntityManagerFactory().findEntityGraphsByType( entityClass );
}
@Override
public GraphImplementor getFetchGraphLoadContext() {
return this.fetchGraphLoadContext;
}
@Override
public void setFetchGraphLoadContext(GraphImplementor fetchGraphLoadContext) {
this.fetchGraphLoadContext = fetchGraphLoadContext;
}
/**
* Used by JDK serialization...
*

View File

@ -1437,9 +1437,6 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
sessionCacheMode = getProducer().getCacheMode();
getProducer().setCacheMode( effectiveCacheMode );
}
if ( entityGraphQueryHint != null && entityGraphQueryHint.getSemantic() == GraphSemantic.FETCH ) {
getProducer().setFetchGraphLoadContext( entityGraphQueryHint.getGraph() );
}
}
protected void afterQuery() {
@ -1451,7 +1448,6 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
getProducer().setCacheMode( sessionCacheMode );
sessionCacheMode = null;
}
getProducer().setFetchGraphLoadContext( null );
}
@Override