docs: private void leaveTransaction(EntityManager em, Object transaction) {
          if( isJTA ) { 
              try { 
                  if( transaction != null ) { 
                      // There's a tx running, close it.
                      ((UserTransaction) transaction).commit();
                  }
              } catch(Exception e) { 
                  logger.error("Unable to commit transaction: ", e);
              }
          } else { 
              if( transaction != null ) { 
                  ((EntityTransaction) transaction).commit();
              }
          }
          
  
          if (!sharedEM) {
              try {  
                  em.flush();
                  em.close(); 
              } catch( Exception e ) { 
                  logger.error("Unable to close created EntityManager: {}", e.getMessage(), e);
              }
          }
      }