public SessionInfo persist(SessionInfo entity) {
   this.em.persist(entity);
   if (this.pessimisticLocking) {
     return this.em.find(
         SessionInfo.class, entity.getId(), LockModeType.PESSIMISTIC_FORCE_INCREMENT);
   }
   return entity;
 }
  public void commit(boolean transactionOwner) {
    // Do not check if the caller is the transactionOwner
    //  because there's no need to "wait" for a commit
    try {
      for (SessionInfo sessionInfo : session.getStoredKnowledgeSessions()) {
        sessionInfo.transform();
        storage.saveOrUpdate(sessionInfo);
      }

      for (WorkItemInfo workItemInfo : session.getStoredWorkItems()) {
        workItemInfo.transform();
        storage.saveOrUpdate(workItemInfo);
      }
      try {
        transactionSynchronization.afterCompletion(TransactionManager.STATUS_COMMITTED);
      } catch (RuntimeException re) {
        logger.warn("Unable to synchronize transaction after commit, see cause.", re);
      }
    } catch (RuntimeException re) {
      transactionSynchronization.afterCompletion(TransactionManager.STATUS_ROLLEDBACK);
    }
    // We shouldn't clear session here because by doing so
    //  we lose track of this objects on successive interactions
  }
 public int getSessionId() {
   return sessionInfo.getId();
 }
 public void saveOrUpdate(SessionInfo storedObject) {
   ksessions.put(storedObject.getId(), storedObject);
 }