Esempio n. 1
0
  @Override
  public boolean storeUser(User u) throws Exception {
    dLog.info("Entering method storeUser | User ID: " + u.getId());
    boolean result = false;
    Session session = null;

    try {
      // ensure we were passed a valid object before attempting to write
      if (u.validate()) {
        session = getSession();
        Transaction tranx = session.beginTransaction();
        session.save(u);
        tranx.commit();
        result = tranx.wasCommitted();
        dLog.info("Was committed: " + result);
      }
    } catch (Exception e) {
      dLog.error("Exception in storeUser", e);
    } finally {
      // ensure that session is close regardless of the errors in try/catch
      if (session != null) {
        session.close();
      }
    }

    return result;
  }