19
19
import java .util .SortedMap ;
20
20
import java .util .TreeMap ;
21
21
22
+ import org .checkerframework .checker .nullness .qual .Nullable ;
22
23
import org .hibernate .Hibernate ;
23
24
import org .hibernate .HibernateException ;
24
25
import org .hibernate .MappingException ;
48
49
49
50
import org .jboss .logging .Logger ;
50
51
52
+ import org .checkerframework .checker .nullness .qual .Nullable ;
53
+
51
54
/**
52
55
* A type that handles Hibernate {@code PersistentCollection}s (including arrays).
53
56
*
@@ -366,7 +369,7 @@ public ForeignKeyDirection getForeignKeyDirection() {
366
369
* @param session The session from which the request is originating.
367
370
* @return The collection owner's key
368
371
*/
369
- public Object getKeyOfOwner (Object owner , SharedSessionContractImplementor session ) {
372
+ public @ Nullable Object getKeyOfOwner (Object owner , SharedSessionContractImplementor session ) {
370
373
final PersistenceContext pc = session .getPersistenceContextInternal ();
371
374
372
375
EntityEntry entityEntry = pc .getEntry ( owner );
@@ -380,28 +383,10 @@ public Object getKeyOfOwner(Object owner, SharedSessionContractImplementor sessi
380
383
return entityEntry .getId ();
381
384
}
382
385
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 ;
386
+ final Object loadedValue = entityEntry .getLoadedValue ( foreignKeyPropertyName );
387
+ return loadedValue == null
388
+ ? entityEntry .getPersister ().getPropertyValue ( owner , foreignKeyPropertyName )
389
+ : loadedValue ;
405
390
}
406
391
}
407
392
0 commit comments