@@ -354,10 +354,10 @@ protected void applyQuerySettingsAndHints(Query<?> query) {
354
354
}
355
355
}
356
356
357
- private Object getSessionProperty (final String name ) {
357
+ private Object getSessionProperty (String propertyName ) {
358
358
return properties == null
359
- ? fastSessionServices .defaultSessionProperties .get ( name )
360
- : properties .get ( name );
359
+ ? fastSessionServices .defaultSessionProperties .get ( propertyName )
360
+ : properties .get ( propertyName );
361
361
}
362
362
363
363
@ Override
@@ -464,9 +464,7 @@ protected boolean shouldCloseJdbcCoordinatorOnClose(boolean isTransactionCoordin
464
464
465
465
final ActionQueue actionQueue = getActionQueue ();
466
466
if ( actionQueue .hasBeforeTransactionActions () || actionQueue .hasAfterTransactionActions () ) {
467
- log .warn (
468
- "On close, shared Session had before/after transaction actions that have not yet been processed"
469
- );
467
+ log .warn ( "On close, shared Session had before/after transaction actions that have not yet been processed" );
470
468
}
471
469
return false ;
472
470
}
@@ -575,11 +573,8 @@ public LockMode getCurrentLockMode(Object object) throws HibernateException {
575
573
}
576
574
577
575
if ( e .getStatus ().isDeletedOrGone () ) {
578
- throw new ObjectDeletedException (
579
- "The given object was deleted" ,
580
- e .getId (),
581
- e .getPersister ().getEntityName ()
582
- );
576
+ throw new ObjectDeletedException ( "The given object was deleted" , e .getId (),
577
+ e .getPersister ().getEntityName () );
583
578
}
584
579
585
580
return e .getLockMode ();
@@ -895,6 +890,7 @@ private void logRemoveOrphanBeforeUpdates(String timing, String entityName, Obje
895
890
}
896
891
897
892
private void fireDelete (final DeleteEvent event ) {
893
+ checkEntityManagedIfJpa ( event .getEntityName (), event .getObject () );
898
894
try {
899
895
pulseTransactionCoordinator ();
900
896
fastSessionServices .eventListenerGroup_DELETE
@@ -916,6 +912,7 @@ private void fireDelete(final DeleteEvent event) {
916
912
}
917
913
918
914
private void fireDelete (final DeleteEvent event , final DeleteContext transientEntities ) {
915
+ checkEntityManagedIfJpa ( event .getEntityName (), event .getObject () );
919
916
try {
920
917
pulseTransactionCoordinator ();
921
918
fastSessionServices .eventListenerGroup_DELETE
@@ -1204,8 +1201,17 @@ private void fireRefresh(final RefreshContext refreshedAlready, final RefreshEve
1204
1201
private void checkEntityManaged (String entityName , Object entity ) {
1205
1202
if ( !getSessionFactory ().getSessionFactoryOptions ().isAllowRefreshDetachedEntity () ) {
1206
1203
if ( !managed ( entityName , entity ) ) {
1207
- throw new IllegalArgumentException (
1208
- "Given entity is not associated with the persistence context" );
1204
+ throw new IllegalArgumentException ( "Given entity is not associated with the persistence context" );
1205
+ }
1206
+ }
1207
+ }
1208
+
1209
+ private void checkEntityManagedIfJpa (String entityName , Object entity ) {
1210
+ if ( getSessionFactory ().getSessionFactoryOptions ().isJpaBootstrap () ) {
1211
+ if ( !managed ( entityName , entity )
1212
+ // just in case it was already deleted
1213
+ && !persistenceContext .isEntryFor ( entity ) ) {
1214
+ throw new IllegalArgumentException ( "Given entity is not associated with the persistence context" );
1209
1215
}
1210
1216
}
1211
1217
}
@@ -1423,8 +1429,9 @@ public Object getIdentifier(Object object) throws HibernateException {
1423
1429
}
1424
1430
1425
1431
/**
1426
- * Get the id value for an object that is actually associated with the session. This
1427
- * is a bit stricter than getEntityIdentifierIfNotUnsaved().
1432
+ * Get the id value for an object that is actually associated with the session.
1433
+ * This is a bit stricter than
1434
+ * {@link org.hibernate.engine.internal.ForeignKeys#getEntityIdentifierIfNotUnsaved}.
1428
1435
*/
1429
1436
@ Override
1430
1437
public Object getContextEntityIdentifier (Object object ) {
@@ -1457,20 +1464,20 @@ public boolean contains(Object object) {
1457
1464
try {
1458
1465
final LazyInitializer lazyInitializer = extractLazyInitializer ( object );
1459
1466
if ( lazyInitializer != null ) {
1460
- //do not use proxiesByKey, since not all
1461
- //proxies that point to this session's
1462
- //instances are in that collection!
1467
+ // don't use proxiesByKey, since not all
1468
+ // proxies that point to this session's
1469
+ // instances are in that collection!
1463
1470
if ( lazyInitializer .isUninitialized () ) {
1464
- //if it is an uninitialized proxy, pointing
1465
- //with this session, then when it is accessed,
1466
- //the underlying instance will be "contained"
1471
+ // if it's an uninitialized proxy associated
1472
+ // with this session, then when it is accessed,
1473
+ // the underlying instance will be "contained"
1467
1474
return lazyInitializer .getSession () == this ;
1468
1475
}
1469
1476
else {
1470
- //if it is initialized, see if the underlying
1471
- //instance is contained, since we need to
1472
- //account for the fact that it might have been
1473
- //evicted
1477
+ // if it's initialized, see if the underlying
1478
+ // instance is contained, since we need to
1479
+ // account for the fact that it might have been
1480
+ // evicted
1474
1481
object = lazyInitializer .getImplementation ();
1475
1482
}
1476
1483
}
0 commit comments