static void unboundSfsbFromExtendedPC ( JPAExPcBindingContext bindingContext ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) Tr . entry ( tc , "unboundSfsbFromExtendedPC : " + bindingContext ) ; JPAPuId puIds [ ] = bindingContext . getExPcPuIds ( ) ; long bindId = bindingContext . getBindId ( ) ; // New this binding key only once and update the puid in the loop ExPcBindingKey bindingKey = new ExPcBindingKey ( bindId , null ) ; for ( JPAPuId puId : puIds ) { bindingKey . puId = puId ; ExPcBindingInfo exPcBindingInfo = svExPcBindingMap . remove ( bindingKey ) ; if ( exPcBindingInfo != null ) { // JPA 5.9.1 Container Responsibilities // // The container closes the entity manager by calling EntityManager.close after the // stateful session bean and all other stateful session beans that have inherited // the same persistence context as the EntityManager have been removed. if ( exPcBindingInfo . removeRemovedOrDiscardedSfsb ( bindingKey ) == 0 ) { EntityManager em = exPcBindingInfo . getEntityManager ( ) ; if ( em != null ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( tc , "All SFSBs using the same extend-scoped persistence " + "context have been removed, closing EntityManager " + em ) ; if ( em . isOpen ( ) ) // d442445 em . close ( ) ; } } } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) Tr . exit ( tc , "unboundSfsbFromExtendedPC : exPcBindMap size=" + svExPcBindingMap . size ( ) ) ; }
When SFSB instances are removed or discard this method is called to unbind the SFSB from the associated persistence context . When the last SFSB is removed from the bound collection the associated EntityManager is closed .