mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-03-01 23:39:15 +00:00
HHH-14212 revert back HHH-14124 (retaining testing case)
This commit is contained in:
parent
cadc3bf9dc
commit
d1f9469cac
@ -68,7 +68,6 @@
|
|||||||
import org.hibernate.event.spi.PostLoadEvent;
|
import org.hibernate.event.spi.PostLoadEvent;
|
||||||
import org.hibernate.event.spi.PreLoadEvent;
|
import org.hibernate.event.spi.PreLoadEvent;
|
||||||
import org.hibernate.event.spi.PreLoadEventListener;
|
import org.hibernate.event.spi.PreLoadEventListener;
|
||||||
import org.hibernate.graph.spi.GraphImplementor;
|
|
||||||
import org.hibernate.hql.internal.HolderInstantiator;
|
import org.hibernate.hql.internal.HolderInstantiator;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
@ -381,8 +380,8 @@ public Object loadSingleRow(
|
|||||||
final boolean returnProxies) throws HibernateException {
|
final boolean returnProxies) throws HibernateException {
|
||||||
|
|
||||||
final int entitySpan = getEntityPersisters().length;
|
final int entitySpan = getEntityPersisters().length;
|
||||||
final List<Object> hydratedObjects = entitySpan == 0 ?
|
final List hydratedObjects = entitySpan == 0 ?
|
||||||
null : new ArrayList<>( entitySpan );
|
null : new ArrayList( entitySpan );
|
||||||
|
|
||||||
final Object result;
|
final Object result;
|
||||||
try {
|
try {
|
||||||
@ -423,8 +422,8 @@ private Object sequentialLoad(
|
|||||||
final EntityKey keyToRead) throws HibernateException {
|
final EntityKey keyToRead) throws HibernateException {
|
||||||
|
|
||||||
final int entitySpan = getEntityPersisters().length;
|
final int entitySpan = getEntityPersisters().length;
|
||||||
final List<Object> nullSeparatedHydratedObjects = entitySpan == 0 ?
|
final List hydratedObjects = entitySpan == 0 ?
|
||||||
null : new ArrayList<>( entitySpan );
|
null : new ArrayList( entitySpan );
|
||||||
|
|
||||||
Object result = null;
|
Object result = null;
|
||||||
final EntityKey[] loadedKeys = new EntityKey[entitySpan];
|
final EntityKey[] loadedKeys = new EntityKey[entitySpan];
|
||||||
@ -437,14 +436,10 @@ private Object sequentialLoad(
|
|||||||
queryParameters,
|
queryParameters,
|
||||||
getLockModes( queryParameters.getLockOptions() ),
|
getLockModes( queryParameters.getLockOptions() ),
|
||||||
null,
|
null,
|
||||||
nullSeparatedHydratedObjects,
|
hydratedObjects,
|
||||||
loadedKeys,
|
loadedKeys,
|
||||||
returnProxies
|
returnProxies
|
||||||
);
|
);
|
||||||
if ( nullSeparatedHydratedObjects != null ) {
|
|
||||||
// Signal that a new row starts. Used in initializeEntitiesAndCollections
|
|
||||||
nullSeparatedHydratedObjects.add( null );
|
|
||||||
}
|
|
||||||
if ( !keyToRead.equals( loadedKeys[0] ) ) {
|
if ( !keyToRead.equals( loadedKeys[0] ) ) {
|
||||||
throw new AssertionFailure(
|
throw new AssertionFailure(
|
||||||
String.format(
|
String.format(
|
||||||
@ -470,7 +465,7 @@ private Object sequentialLoad(
|
|||||||
}
|
}
|
||||||
|
|
||||||
initializeEntitiesAndCollections(
|
initializeEntitiesAndCollections(
|
||||||
nullSeparatedHydratedObjects,
|
hydratedObjects,
|
||||||
resultSet,
|
resultSet,
|
||||||
session,
|
session,
|
||||||
queryParameters.isReadOnly( session )
|
queryParameters.isReadOnly( session )
|
||||||
@ -701,7 +696,7 @@ private Object getRowFromResultSet(
|
|||||||
final QueryParameters queryParameters,
|
final QueryParameters queryParameters,
|
||||||
final LockMode[] lockModesArray,
|
final LockMode[] lockModesArray,
|
||||||
final EntityKey optionalObjectKey,
|
final EntityKey optionalObjectKey,
|
||||||
final List<Object> hydratedObjects,
|
final List hydratedObjects,
|
||||||
final EntityKey[] keys,
|
final EntityKey[] keys,
|
||||||
boolean returnProxies) throws SQLException, HibernateException {
|
boolean returnProxies) throws SQLException, HibernateException {
|
||||||
return getRowFromResultSet(
|
return getRowFromResultSet(
|
||||||
@ -723,7 +718,7 @@ private Object getRowFromResultSet(
|
|||||||
final QueryParameters queryParameters,
|
final QueryParameters queryParameters,
|
||||||
final LockMode[] lockModesArray,
|
final LockMode[] lockModesArray,
|
||||||
final EntityKey optionalObjectKey,
|
final EntityKey optionalObjectKey,
|
||||||
final List<Object> hydratedObjects,
|
final List hydratedObjects,
|
||||||
final EntityKey[] keys,
|
final EntityKey[] keys,
|
||||||
boolean returnProxies,
|
boolean returnProxies,
|
||||||
ResultTransformer forcedResultTransformer) throws SQLException, HibernateException {
|
ResultTransformer forcedResultTransformer) throws SQLException, HibernateException {
|
||||||
@ -787,7 +782,7 @@ protected void extractKeysFromResultSet(
|
|||||||
SharedSessionContractImplementor session,
|
SharedSessionContractImplementor session,
|
||||||
EntityKey[] keys,
|
EntityKey[] keys,
|
||||||
LockMode[] lockModes,
|
LockMode[] lockModes,
|
||||||
List<Object> hydratedObjects) throws SQLException {
|
List hydratedObjects) throws SQLException {
|
||||||
final int entitySpan = persisters.length;
|
final int entitySpan = persisters.length;
|
||||||
|
|
||||||
final int numberOfPersistersToProcess;
|
final int numberOfPersistersToProcess;
|
||||||
@ -990,7 +985,7 @@ protected List processResultSet(
|
|||||||
final int entitySpan = getEntityPersisters().length;
|
final int entitySpan = getEntityPersisters().length;
|
||||||
final boolean createSubselects = isSubselectLoadingEnabled();
|
final boolean createSubselects = isSubselectLoadingEnabled();
|
||||||
final List<EntityKey[]> subselectResultKeys = createSubselects ? new ArrayList<>() : null;
|
final List<EntityKey[]> subselectResultKeys = createSubselects ? new ArrayList<>() : null;
|
||||||
final List<Object> nullSeparatedHydratedObjectsPerRow = entitySpan == 0 ? null : new ArrayList<>();
|
final List<Object> hydratedObjects = entitySpan == 0 ? null : new ArrayList<>( entitySpan * 10 );
|
||||||
|
|
||||||
final List results = getRowsFromResultSet(
|
final List results = getRowsFromResultSet(
|
||||||
rs,
|
rs,
|
||||||
@ -999,12 +994,12 @@ protected List processResultSet(
|
|||||||
returnProxies,
|
returnProxies,
|
||||||
forcedResultTransformer,
|
forcedResultTransformer,
|
||||||
maxRows,
|
maxRows,
|
||||||
nullSeparatedHydratedObjectsPerRow,
|
hydratedObjects,
|
||||||
subselectResultKeys
|
subselectResultKeys
|
||||||
);
|
);
|
||||||
|
|
||||||
initializeEntitiesAndCollections(
|
initializeEntitiesAndCollections(
|
||||||
nullSeparatedHydratedObjectsPerRow,
|
hydratedObjects,
|
||||||
rs,
|
rs,
|
||||||
session,
|
session,
|
||||||
queryParameters.isReadOnly( session ),
|
queryParameters.isReadOnly( session ),
|
||||||
@ -1023,7 +1018,7 @@ protected List<Object> getRowsFromResultSet(
|
|||||||
boolean returnProxies,
|
boolean returnProxies,
|
||||||
ResultTransformer forcedResultTransformer,
|
ResultTransformer forcedResultTransformer,
|
||||||
int maxRows,
|
int maxRows,
|
||||||
List<Object> nullSeparatedHydratedObjects,
|
List<Object> hydratedObjects,
|
||||||
List<EntityKey[]> subselectResultKeys) throws SQLException {
|
List<EntityKey[]> subselectResultKeys) throws SQLException {
|
||||||
final int entitySpan = getEntityPersisters().length;
|
final int entitySpan = getEntityPersisters().length;
|
||||||
final boolean createSubselects = isSubselectLoadingEnabled();
|
final boolean createSubselects = isSubselectLoadingEnabled();
|
||||||
@ -1047,16 +1042,12 @@ protected List<Object> getRowsFromResultSet(
|
|||||||
queryParameters,
|
queryParameters,
|
||||||
lockModesArray,
|
lockModesArray,
|
||||||
optionalObjectKey,
|
optionalObjectKey,
|
||||||
nullSeparatedHydratedObjects,
|
hydratedObjects,
|
||||||
keys,
|
keys,
|
||||||
returnProxies,
|
returnProxies,
|
||||||
forcedResultTransformer
|
forcedResultTransformer
|
||||||
);
|
);
|
||||||
results.add( result );
|
results.add( result );
|
||||||
if ( nullSeparatedHydratedObjects != null ) {
|
|
||||||
// Signal that a new row starts. Used in initializeEntitiesAndCollections
|
|
||||||
nullSeparatedHydratedObjects.add( null );
|
|
||||||
}
|
|
||||||
if ( createSubselects ) {
|
if ( createSubselects ) {
|
||||||
subselectResultKeys.add( keys );
|
subselectResultKeys.add( keys );
|
||||||
keys = new EntityKey[entitySpan]; //can't reuse in this case
|
keys = new EntityKey[entitySpan]; //can't reuse in this case
|
||||||
@ -1147,12 +1138,12 @@ private Map buildNamedParameterLocMap(QueryParameters queryParameters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeEntitiesAndCollections(
|
private void initializeEntitiesAndCollections(
|
||||||
final List<Object> nullSeparatedHydratedObjects,
|
final List hydratedObjects,
|
||||||
final Object resultSetId,
|
final Object resultSetId,
|
||||||
final SharedSessionContractImplementor session,
|
final SharedSessionContractImplementor session,
|
||||||
final boolean readOnly) throws HibernateException {
|
final boolean readOnly) throws HibernateException {
|
||||||
initializeEntitiesAndCollections(
|
initializeEntitiesAndCollections(
|
||||||
nullSeparatedHydratedObjects,
|
hydratedObjects,
|
||||||
resultSetId,
|
resultSetId,
|
||||||
session,
|
session,
|
||||||
readOnly,
|
readOnly,
|
||||||
@ -1161,7 +1152,7 @@ private void initializeEntitiesAndCollections(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeEntitiesAndCollections(
|
private void initializeEntitiesAndCollections(
|
||||||
final List<Object> nullSeparatedHydratedObjects,
|
final List hydratedObjects,
|
||||||
final Object resultSetId,
|
final Object resultSetId,
|
||||||
final SharedSessionContractImplementor session,
|
final SharedSessionContractImplementor session,
|
||||||
final boolean readOnly,
|
final boolean readOnly,
|
||||||
@ -1193,17 +1184,11 @@ private void initializeEntitiesAndCollections(
|
|||||||
post = null;
|
post = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( nullSeparatedHydratedObjects != null && !nullSeparatedHydratedObjects.isEmpty() ) {
|
if ( hydratedObjects != null ) {
|
||||||
if ( LOG.isTraceEnabled() ) {
|
int hydratedObjectsSize = hydratedObjects.size();
|
||||||
int hydratedObjectsSize = 0;
|
|
||||||
for ( Object hydratedObject : nullSeparatedHydratedObjects ) {
|
|
||||||
if ( hydratedObject != null ) {
|
|
||||||
++hydratedObjectsSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize );
|
LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize );
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( hydratedObjectsSize != 0 ) {
|
||||||
final Iterable<PreLoadEventListener> listeners = session
|
final Iterable<PreLoadEventListener> listeners = session
|
||||||
.getFactory()
|
.getFactory()
|
||||||
.getServiceRegistry()
|
.getServiceRegistry()
|
||||||
@ -1211,22 +1196,10 @@ private void initializeEntitiesAndCollections(
|
|||||||
.getEventListenerGroup( EventType.PRE_LOAD )
|
.getEventListenerGroup( EventType.PRE_LOAD )
|
||||||
.listeners();
|
.listeners();
|
||||||
|
|
||||||
GraphImplementor<?> fetchGraphLoadContextToRestore = session.getFetchGraphLoadContext();
|
for ( Object hydratedObject : hydratedObjects ) {
|
||||||
for ( Object hydratedObject : nullSeparatedHydratedObjects ) {
|
TwoPhaseLoad.initializeEntity( hydratedObject, readOnly, session, pre, listeners );
|
||||||
if ( hydratedObject == null ) {
|
|
||||||
// This is a hack to signal that we're starting to process a new row
|
|
||||||
|
|
||||||
// HHH-14124: TwoPhaseLoad has nasty side-effects in order to handle sub-graphs.
|
|
||||||
// That's very fragile, but someone would need to spend much more time on this
|
|
||||||
// in order to implement it correctly, and apparently that's already been done in ORM 6.0.
|
|
||||||
// So for now, we'll just ensure side-effects (and whatever bugs they lead to)
|
|
||||||
// are limited to each row.
|
|
||||||
session.setFetchGraphLoadContext( fetchGraphLoadContextToRestore );
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TwoPhaseLoad.initializeEntity( hydratedObject, readOnly, session, pre, listeners );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1242,13 +1215,8 @@ private void initializeEntitiesAndCollections(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( nullSeparatedHydratedObjects != null ) {
|
if ( hydratedObjects != null ) {
|
||||||
for ( Object hydratedObject : nullSeparatedHydratedObjects ) {
|
for ( Object hydratedObject : hydratedObjects ) {
|
||||||
if ( hydratedObject == null ) {
|
|
||||||
// This is a hack to signal that we're starting to process a new row
|
|
||||||
// Ignore
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TwoPhaseLoad.afterInitialize( hydratedObject, session );
|
TwoPhaseLoad.afterInitialize( hydratedObject, session );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1258,13 +1226,8 @@ private void initializeEntitiesAndCollections(
|
|||||||
// endCollectionLoad to ensure the collection is in the
|
// endCollectionLoad to ensure the collection is in the
|
||||||
// persistence context.
|
// persistence context.
|
||||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||||
if ( nullSeparatedHydratedObjects != null && !nullSeparatedHydratedObjects.isEmpty() ) {
|
if ( hydratedObjects != null && hydratedObjects.size() > 0 ) {
|
||||||
for ( Object hydratedObject : nullSeparatedHydratedObjects ) {
|
for ( Object hydratedObject : hydratedObjects ) {
|
||||||
if ( hydratedObject == null ) {
|
|
||||||
// This is a hack to signal that we're starting to process a new row
|
|
||||||
// Ignore
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TwoPhaseLoad.postLoad( hydratedObject, session, post );
|
TwoPhaseLoad.postLoad( hydratedObject, session, post );
|
||||||
if ( afterLoadActions != null ) {
|
if ( afterLoadActions != null ) {
|
||||||
for ( AfterLoadAction afterLoadAction : afterLoadActions ) {
|
for ( AfterLoadAction afterLoadAction : afterLoadActions ) {
|
||||||
@ -1622,7 +1585,7 @@ private Object[] getRow(
|
|||||||
final Object optionalObject,
|
final Object optionalObject,
|
||||||
final EntityKey optionalObjectKey,
|
final EntityKey optionalObjectKey,
|
||||||
final LockMode[] lockModes,
|
final LockMode[] lockModes,
|
||||||
final List<Object> hydratedObjects,
|
final List hydratedObjects,
|
||||||
final SharedSessionContractImplementor session) throws HibernateException, SQLException {
|
final SharedSessionContractImplementor session) throws HibernateException, SQLException {
|
||||||
final int cols = persisters.length;
|
final int cols = persisters.length;
|
||||||
final EntityAliases[] entityAliases = getEntityAliases();
|
final EntityAliases[] entityAliases = getEntityAliases();
|
||||||
@ -1689,7 +1652,7 @@ protected void instanceAlreadyLoaded(
|
|||||||
final EntityKey key,
|
final EntityKey key,
|
||||||
final Object object,
|
final Object object,
|
||||||
final LockMode requestedLockMode,
|
final LockMode requestedLockMode,
|
||||||
List<Object> hydratedObjects,
|
List hydratedObjects,
|
||||||
final SharedSessionContractImplementor session)
|
final SharedSessionContractImplementor session)
|
||||||
throws HibernateException, SQLException {
|
throws HibernateException, SQLException {
|
||||||
if ( !persister.isInstance( object ) ) {
|
if ( !persister.isInstance( object ) ) {
|
||||||
@ -1757,7 +1720,7 @@ protected Object instanceNotYetLoaded(
|
|||||||
final LockMode lockMode,
|
final LockMode lockMode,
|
||||||
final EntityKey optionalObjectKey,
|
final EntityKey optionalObjectKey,
|
||||||
final Object optionalObject,
|
final Object optionalObject,
|
||||||
final List<Object> hydratedObjects,
|
final List hydratedObjects,
|
||||||
final SharedSessionContractImplementor session)
|
final SharedSessionContractImplementor session)
|
||||||
throws HibernateException, SQLException {
|
throws HibernateException, SQLException {
|
||||||
final String instanceClass = getInstanceClass(
|
final String instanceClass = getInstanceClass(
|
||||||
|
@ -42,7 +42,6 @@
|
|||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
* @author Nathan Xu
|
* @author Nathan Xu
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-14097")
|
|
||||||
public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase {
|
public class LoadAndFetchGraphTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -180,6 +179,7 @@ public void setUp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14097")
|
||||||
public void testQueryById() {
|
public void testQueryById() {
|
||||||
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
@ -205,6 +205,7 @@ public void testQueryById() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14097")
|
||||||
public void testQueryByIdWithLoadGraph() {
|
public void testQueryByIdWithLoadGraph() {
|
||||||
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
@ -241,6 +242,7 @@ public void testQueryByIdWithLoadGraph() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14097")
|
||||||
public void testQueryByIdWithFetchGraph() {
|
public void testQueryByIdWithFetchGraph() {
|
||||||
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
@ -275,6 +277,7 @@ public void testQueryByIdWithFetchGraph() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-14097")
|
||||||
public void testQueryByIdWithFetchGraph2() {
|
public void testQueryByIdWithFetchGraph2() {
|
||||||
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
Statistics statistics = entityManagerFactory().unwrap( SessionFactory.class ).getStatistics();
|
||||||
statistics.clear();
|
statistics.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user