Skip to content

Commit c58cd97

Browse files
committed
HHH-15223 Embeddables in the Query Result, the embeddable instance returned by the query will not be in the managed state
1 parent c0df74f commit c58cd97

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableResultImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
public class EmbeddableResultImpl<T> extends AbstractFetchParent implements EmbeddableResultGraphNode, DomainResult<T>, EmbeddableResult<T> {
3434
private final String resultVariable;
3535
private final boolean containsAnyNonScalars;
36+
private final NavigablePath initializerNavigablePath;
3637

3738
public EmbeddableResultImpl(
3839
NavigablePath navigablePath,
@@ -41,6 +42,12 @@ public EmbeddableResultImpl(
4142
DomainResultCreationState creationState) {
4243
super( modelPart.getEmbeddableTypeDescriptor(), navigablePath );
4344
this.resultVariable = resultVariable;
45+
/*
46+
An `{embeddable_result}` sub-path is created for the corresponding initializer to differentiate it from a fetch-initializer if this embedded is also fetched.
47+
The Jakarta Persistence spec says that any embedded value selected in the result should not be part of the state of any managed entity.
48+
Using this `{embeddable_result}` sub-path avoids this situation.
49+
*/
50+
this.initializerNavigablePath = navigablePath.append( "{embeddable_result}" );
4451

4552
final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
4653

@@ -114,7 +121,7 @@ public DomainResultAssembler<T> createResultAssembler(
114121
FetchParentAccess parentAccess,
115122
AssemblerCreationState creationState) {
116123
final EmbeddableInitializer initializer = (EmbeddableInitializer) creationState.resolveInitializer(
117-
getNavigablePath(),
124+
initializerNavigablePath,
118125
getReferencedModePart(),
119126
() -> new EmbeddableResultInitializer(
120127
this,

0 commit comments

Comments
 (0)