Skip to content

Commit 0462773

Browse files
committed
delete unnecessary branch in SessionImpl
1 parent 53f6f9a commit 0462773

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,31 +1247,23 @@ public <T> NaturalIdMultiLoadAccess<T> byMultipleNaturalId(String entityName) {
12471247

12481248
@Override
12491249
public Object load(LoadType loadType, Object id, String entityName, LockOptions lockOptions, Boolean readOnly) {
1250-
if ( lockOptions != null ) {
1251-
// TODO: I doubt that this branch is necessary, and it's probably even wrong
1252-
final var event = makeLoadEvent( entityName, id, readOnly, lockOptions );
1250+
boolean success = false;
1251+
try {
1252+
final var event =
1253+
makeLoadEvent( entityName, id, readOnly,
1254+
lockOptions == null ? LockOptions.NONE : lockOptions );
12531255
fireLoad( event, loadType );
12541256
final Object result = event.getResult();
12551257
releaseLoadEvent( event );
1258+
if ( !loadType.isAllowNulls() && result == null ) {
1259+
getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
1260+
}
1261+
success = true;
12561262
return result;
12571263
}
1258-
else {
1259-
boolean success = false;
1260-
try {
1261-
final var event = makeLoadEvent( entityName, id, readOnly, false );
1262-
fireLoad( event, loadType );
1263-
final Object result = event.getResult();
1264-
releaseLoadEvent( event );
1265-
if ( !loadType.isAllowNulls() && result == null ) {
1266-
getSession().getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id );
1267-
}
1268-
success = true;
1269-
return result;
1270-
}
1271-
finally {
1272-
// we might be called from outside transaction
1273-
afterOperation( success );
1274-
}
1264+
finally {
1265+
// we might be called from outside transaction
1266+
afterOperation( success );
12751267
}
12761268
}
12771269

hibernate-core/src/main/java/org/hibernate/loader/internal/IdentifierLoadAccessImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,15 @@ protected T perform(Supplier<T> executor) {
138138
}
139139
}
140140

141-
@SuppressWarnings( "unchecked" )
142141
// Hibernate Reactive overrides this
143142
protected T doGetReference(Object id) {
144143
final var session = context.getSession();
145144
final var concreteType = entityPersister.resolveConcreteProxyTypeForId( id, session );
146-
return (T) context.load( LoadEventListener.LOAD, coerceId( id, session.getFactory() ),
147-
concreteType.getEntityName(), lockOptions, isReadOnly( session ) );
145+
final Object result =
146+
context.load( LoadEventListener.LOAD, coerceId( id, session.getFactory() ),
147+
concreteType.getEntityName(), lockOptions, isReadOnly( session ) );
148+
//noinspection unchecked
149+
return (T) result;
148150
}
149151

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

167-
@SuppressWarnings( "unchecked" )
168169
// Hibernate Reactive overrides this
169170
protected T doLoad(Object id) {
170171
final var session = context.getSession();
171172
Object result;
172173
try {
173-
result = context.load( LoadEventListener.GET, coerceId( id, session.getFactory() ),
174-
entityPersister.getEntityName(), lockOptions, isReadOnly( session ) );
174+
result =
175+
context.load( LoadEventListener.GET, coerceId( id, session.getFactory() ),
176+
entityPersister.getEntityName(), lockOptions, isReadOnly( session ) );
175177
}
176178
catch (ObjectNotFoundException notFoundException) {
177-
// if session cache contains proxy for non-existing object
179+
// if session cache contains proxy for nonexisting object
178180
result = null;
179181
}
180182
initializeIfNecessary( result );
183+
//noinspection unchecked
181184
return (T) result;
182185
}
183186

0 commit comments

Comments
 (0)