HHH-16745 Consider loading entity entries when checking if transient
This commit is contained in:
parent
ab0f320cd2
commit
75adba3376
|
@ -266,6 +266,7 @@ import org.hibernate.sql.results.graph.Fetch;
|
|||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.sql.results.graph.Fetchable;
|
||||
import org.hibernate.sql.results.graph.FetchableContainer;
|
||||
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
|
||||
import org.hibernate.sql.results.graph.entity.internal.EntityResultImpl;
|
||||
import org.hibernate.sql.results.graph.internal.ImmutableFetchList;
|
||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||
|
@ -3862,12 +3863,23 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
// check the version unsaved-value, if appropriate
|
||||
final Object version = getVersion( entity );
|
||||
if ( isVersioned() ) {
|
||||
// let this take precedence if defined, since it works for
|
||||
// assigned identifiers
|
||||
final Object version = getVersion( entity );
|
||||
final Boolean result = versionMapping.getUnsavedStrategy().isUnsaved( version );
|
||||
if ( result != null ) {
|
||||
if ( result && version == null && session.getPersistenceContext().hasLoadContext() ) {
|
||||
// check if we're currently loading this entity instance, the version
|
||||
// will be null but the entity cannot be considered transient
|
||||
final EntityKey entityKey = new EntityKey( id, this );
|
||||
final LoadingEntityEntry loadingEntityEntry = session.getPersistenceContext()
|
||||
.getLoadContexts()
|
||||
.findLoadingEntityEntry( entityKey );
|
||||
if ( loadingEntityEntry != null && loadingEntityEntry.getEntityInstance() == entity ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue