48
48
49
49
import org .jboss .logging .Logger ;
50
50
51
+ import org .checkerframework .checker .nullness .qual .Nullable ;
52
+
51
53
/**
52
54
* A type that handles Hibernate {@code PersistentCollection}s (including arrays).
53
55
*
@@ -366,7 +368,7 @@ public ForeignKeyDirection getForeignKeyDirection() {
366
368
* @param session The session from which the request is originating.
367
369
* @return The collection owner's key
368
370
*/
369
- public Object getKeyOfOwner (Object owner , SharedSessionContractImplementor session ) {
371
+ public @ Nullable getKeyOfOwner (Object owner , SharedSessionContractImplementor session ) {
370
372
final PersistenceContext pc = session .getPersistenceContextInternal ();
371
373
372
374
EntityEntry entityEntry = pc .getEntry ( owner );
@@ -380,28 +382,10 @@ public Object getKeyOfOwner(Object owner, SharedSessionContractImplementor sessi
380
382
return entityEntry .getId ();
381
383
}
382
384
else {
383
- // TODO: at the point where we are resolving collection references, we don't
384
- // know if the uk value has been resolved (depends if it was earlier or
385
- // later in the mapping document) - now, we could try and use e.getStatus()
386
- // to decide to semiResolve(), trouble is that initializeEntity() reuses
387
- // the same array for resolved and hydrated values
388
- Object id = entityEntry .getLoadedState () != null
389
- ? entityEntry .getLoadedValue ( foreignKeyPropertyName )
390
- : entityEntry .getPersister ().getPropertyValue ( owner , foreignKeyPropertyName );
391
-
392
- // NOTE VERY HACKISH WORKAROUND!!
393
- // TODO: Fix this so it will work for non-POJO entity mode
394
- Type keyType = getPersister ( session ).getKeyType ();
395
- if ( !keyType .getReturnedClass ().isInstance ( id ) ) {
396
- throw new UnsupportedOperationException ( "Re-work support for semi-resolve" );
397
- // id = keyType.semiResolve(
398
- // entityEntry.getLoadedValue( foreignKeyPropertyName ),
399
- // session,
400
- // owner
401
- // );
402
- }
403
-
404
- return id ;
385
+ final Object loadedValue = entityEntry .getLoadedValue ( foreignKeyPropertyName );
386
+ return loadedValue == null
387
+ ? entityEntry .getPersister ().getPropertyValue ( owner , foreignKeyPropertyName )
388
+ : loadedValue ;
405
389
}
406
390
}
407
391
0 commit comments