mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-10 05:04:52 +00:00
EagerCollectionFetch generates collection and index fetches twice
This commit is contained in:
parent
dca850f5ad
commit
6aefe00c1e
@ -21,6 +21,7 @@
|
|||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.collection.internal.BagInitializerProducer;
|
import org.hibernate.sql.results.graph.collection.internal.BagInitializerProducer;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
@ -95,4 +96,45 @@ public CollectionInitializerProducer createInitializerProducer(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionInitializerProducer createInitializerProducer(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
FetchParent fetchParent,
|
||||||
|
boolean selected,
|
||||||
|
String resultVariable,
|
||||||
|
LockMode lockMode,
|
||||||
|
Fetch indexFetch,
|
||||||
|
Fetch elementFetch,
|
||||||
|
DomainResultCreationState creationState){
|
||||||
|
if ( indexFetch == null ) {
|
||||||
|
indexFetch = attributeMapping.getIdentifierDescriptor() == null ? null : attributeMapping.getIdentifierDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.ID.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( elementFetch == null ) {
|
||||||
|
elementFetch = attributeMapping.getElementDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new BagInitializerProducer(
|
||||||
|
attributeMapping,
|
||||||
|
indexFetch,
|
||||||
|
elementFetch
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.collection.internal.MapInitializerProducer;
|
import org.hibernate.sql.results.graph.collection.internal.MapInitializerProducer;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
@ -108,4 +108,45 @@ public CollectionInitializerProducer createInitializerProducer(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionInitializerProducer createInitializerProducer(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
FetchParent fetchParent,
|
||||||
|
boolean selected,
|
||||||
|
String resultVariable,
|
||||||
|
LockMode lockMode,
|
||||||
|
Fetch indexFetch,
|
||||||
|
Fetch elementFetch,
|
||||||
|
DomainResultCreationState creationState){
|
||||||
|
if ( indexFetch == null ) {
|
||||||
|
indexFetch = attributeMapping.getIndexDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( elementFetch == null ) {
|
||||||
|
elementFetch = attributeMapping.getElementDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new MapInitializerProducer(
|
||||||
|
attributeMapping,
|
||||||
|
indexFetch,
|
||||||
|
elementFetch
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.collection.internal.SetInitializerProducer;
|
import org.hibernate.sql.results.graph.collection.internal.SetInitializerProducer;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
@ -69,4 +70,29 @@ public CollectionInitializerProducer createInitializerProducer(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionInitializerProducer createInitializerProducer(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
FetchParent fetchParent,
|
||||||
|
boolean selected,
|
||||||
|
String resultVariable,
|
||||||
|
LockMode lockMode,
|
||||||
|
Fetch indexFetch,
|
||||||
|
Fetch elementFetch,
|
||||||
|
DomainResultCreationState creationState){
|
||||||
|
if ( elementFetch == null ) {
|
||||||
|
return createInitializerProducer(
|
||||||
|
navigablePath,
|
||||||
|
attributeMapping,
|
||||||
|
fetchParent,
|
||||||
|
selected,
|
||||||
|
resultVariable,
|
||||||
|
lockMode,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new SetInitializerProducer( attributeMapping, elementFetch );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.collection.internal.ArrayInitializerProducer;
|
import org.hibernate.sql.results.graph.collection.internal.ArrayInitializerProducer;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
@ -126,4 +126,45 @@ public CollectionInitializerProducer createInitializerProducer(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionInitializerProducer createInitializerProducer(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
FetchParent fetchParent,
|
||||||
|
boolean selected,
|
||||||
|
String resultVariable,
|
||||||
|
LockMode lockMode,
|
||||||
|
Fetch indexFetch,
|
||||||
|
Fetch elementFetch,
|
||||||
|
DomainResultCreationState creationState){
|
||||||
|
if ( indexFetch == null ) {
|
||||||
|
indexFetch = attributeMapping.getIndexDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( elementFetch == null ) {
|
||||||
|
elementFetch = attributeMapping.getElementDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new ArrayInitializerProducer(
|
||||||
|
attributeMapping,
|
||||||
|
indexFetch,
|
||||||
|
elementFetch
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.collection.internal.ListInitializerProducer;
|
import org.hibernate.sql.results.graph.collection.internal.ListInitializerProducer;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
@ -101,6 +101,46 @@ public CollectionInitializerProducer createInitializerProducer(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CollectionInitializerProducer createInitializerProducer(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
FetchParent fetchParent,
|
||||||
|
boolean selected,
|
||||||
|
String resultVariable,
|
||||||
|
LockMode lockMode,
|
||||||
|
Fetch indexFetch,
|
||||||
|
Fetch elementFetch,
|
||||||
|
DomainResultCreationState creationState) {
|
||||||
|
if ( indexFetch == null ) {
|
||||||
|
indexFetch = attributeMapping.getIndexDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.INDEX.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( elementFetch == null ) {
|
||||||
|
elementFetch = attributeMapping.getElementDescriptor().generateFetch(
|
||||||
|
fetchParent,
|
||||||
|
navigablePath.append( CollectionPart.Nature.ELEMENT.getName() ),
|
||||||
|
FetchTiming.IMMEDIATE,
|
||||||
|
selected,
|
||||||
|
lockMode,
|
||||||
|
null,
|
||||||
|
creationState
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new ListInitializerProducer(
|
||||||
|
attributeMapping,
|
||||||
|
indexFetch,
|
||||||
|
elementFetch
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PersistentCollection instantiateWrapper(
|
public PersistentCollection instantiateWrapper(
|
||||||
Object key,
|
Object key,
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
import org.hibernate.persister.collection.CollectionPersister;
|
import org.hibernate.persister.collection.CollectionPersister;
|
||||||
import org.hibernate.query.NavigablePath;
|
import org.hibernate.query.NavigablePath;
|
||||||
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,4 +67,15 @@ CollectionInitializerProducer createInitializerProducer(
|
|||||||
String resultVariable,
|
String resultVariable,
|
||||||
LockMode lockMode,
|
LockMode lockMode,
|
||||||
DomainResultCreationState creationState);
|
DomainResultCreationState creationState);
|
||||||
|
|
||||||
|
CollectionInitializerProducer createInitializerProducer(
|
||||||
|
NavigablePath navigablePath,
|
||||||
|
PluralAttributeMapping attributeMapping,
|
||||||
|
FetchParent fetchParent,
|
||||||
|
boolean selected,
|
||||||
|
String resultVariable,
|
||||||
|
LockMode lockMode,
|
||||||
|
Fetch indexFetch,
|
||||||
|
Fetch elementFetch,
|
||||||
|
DomainResultCreationState creationState);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.mapping.Collection;
|
import org.hibernate.mapping.Collection;
|
||||||
import org.hibernate.mapping.Value;
|
import org.hibernate.mapping.Value;
|
||||||
import org.hibernate.metamodel.mapping.Association;
|
|
||||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||||
import org.hibernate.metamodel.mapping.EntityAssociationMapping;
|
import org.hibernate.metamodel.mapping.EntityAssociationMapping;
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
|
@ -98,6 +98,8 @@ public EagerCollectionFetch(
|
|||||||
null,
|
null,
|
||||||
// todo (6.0) : we need to propagate these lock modes
|
// todo (6.0) : we need to propagate these lock modes
|
||||||
LockMode.READ,
|
LockMode.READ,
|
||||||
|
indexFetch,
|
||||||
|
elementFetch,
|
||||||
creationState
|
creationState
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user