public static int updateLegalCustomer(LegalCustomer legalCustomer) {
   Session session = HibernateUtil.getSession();
   try {
     Transaction transaction = session.beginTransaction();
     session.update(legalCustomer);
     transaction.commit();
     logger.info("Legal customer with ID:" + legalCustomer.getID() + " was updated.");
     return SUCCESS;
   } catch (HibernateException e) {
     logger.error("Couldn't update legal customer with ID:" + legalCustomer.getID(), e);
     return FAIL;
   } finally {
     session.close();
   }
 }
 public static List<LegalCustomer> searchLegalCustomer(LegalCustomer sentLegalCustomer) {
   Session session = HibernateUtil.getSession();
   List<LegalCustomer> list = new ArrayList<>();
   try {
     Transaction transaction = session.beginTransaction();
     Criteria criteria = session.createCriteria(LegalCustomer.class);
     if (sentLegalCustomer.checkInfo()) {
       return null;
     }
     if (sentLegalCustomer.getID() != -1) {
       criteria.add(Restrictions.eq("ID", sentLegalCustomer.getID()));
     }
     if (!sentLegalCustomer.getEconomicID().equals("")) {
       criteria.add(Restrictions.eq("economicID", sentLegalCustomer.getEconomicID()));
     }
     if (!sentLegalCustomer.getName().equals("")) {
       criteria.add(Restrictions.eq("name", sentLegalCustomer.getName()));
     }
     list = criteria.list();
     transaction.commit();
     logger.info("User search for legal customers returned " + list.size() + "results.");
     return list;
   } catch (HibernateException ex) {
     ex.printStackTrace();
     logger.error("User tried searching for legal customers. encountered error:", ex);
     return list;
   } finally {
     session.close();
   }
 }
 public static int addNew(LegalCustomer legalCustomer) {
   Session session = HibernateUtil.getSession();
   try {
     Transaction transaction = session.beginTransaction();
     session.save(legalCustomer);
     transaction.commit();
     logger.info(
         "A new legal customer was added to the database with ID:" + legalCustomer.getID());
     return SUCCESS;
   } catch (HibernateException e) {
     logger.error("Adding new legal customer something went wrong.", e);
     return FAIL;
   } finally {
     session.close();
   }
 }