Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1247,31 +1247,23 @@ public <T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(String entityName) {

@Override
public Object load(LoadType loadType, Object id, String entityName, LockOptions lockOptions, Boolean readOnly) {
if ( lockOptions != null ) {
// TODO: I doubt that this branch is necessary, and it's probably even wrong
final var event = makeLoadEvent( entityName, id, readOnly, lockOptions );
boolean success = false;
try {
final var event =
makeLoadEvent( entityName, id, readOnly,
lockOptions == null ? LockOptions.NONE : lockOptions );
fireLoad( event, loadType );
final Object result = event.getResult();
releaseLoadEvent( event );
if ( !loadType.isAllowNulls() && result == null ) {
getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
}
success = true;
return result;
}
else {
boolean success = false;
try {
final var event = makeLoadEvent( entityName, id, readOnly, false );
fireLoad( event, loadType );
final Object result = event.getResult();
releaseLoadEvent( event );
if ( !loadType.isAllowNulls() && result == null ) {
getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
}
success = true;
return result;
}
finally {
// we might be called from outside transaction
afterOperation( success );
}
finally {
// we might be called from outside transaction
afterOperation( success );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ protected T perform(Supplier<T> executor) {
}
}

@SuppressWarnings( "unchecked" )
// Hibernate Reactive overrides this
protected T doGetReference(Object id) {
final var session = context.getSession();
final var concreteType = entityPersister.resolveConcreteProxyTypeForId( id, session );
return (T) context.load( LoadEventListener.LOAD, coerceId( id, session.getFactory() ),
concreteType.getEntityName(), lockOptions, isReadOnly( session ) );
final Object result =
context.load( LoadEventListener.LOAD, coerceId( id, session.getFactory() ),
concreteType.getEntityName(), lockOptions, isReadOnly( session ) );
//noinspection unchecked
return (T) result;
}

// Hibernate Reactive might need to call this
Expand All @@ -164,20 +166,21 @@ public Optional<T> loadOptional(Object id) {
return Optional.ofNullable( perform( () -> doLoad( id ) ) );
}

@SuppressWarnings( "unchecked" )
// Hibernate Reactive overrides this
protected T doLoad(Object id) {
final var session = context.getSession();
Object result;
try {
result = context.load( LoadEventListener.GET, coerceId( id, session.getFactory() ),
entityPersister.getEntityName(), lockOptions, isReadOnly( session ) );
result =
context.load( LoadEventListener.GET, coerceId( id, session.getFactory() ),
entityPersister.getEntityName(), lockOptions, isReadOnly( session ) );
}
catch (ObjectNotFoundException notFoundException) {
// if session cache contains proxy for non-existing object
// if session cache contains proxy for nonexisting object
result = null;
}
initializeIfNecessary( result );
//noinspection unchecked
return (T) result;
}

Expand Down