public static List<PernottamentoEntity> searchByCityDate(
      String city, String checkInDateStr, String checkOutDateStr) {

    List<PernottamentoEntity> pernottamentoList;
    java.util.Date checkInDate, checkOutDate;

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat sdfSQL = new SimpleDateFormat("yyyy/MM/dd");
    try {
      checkInDate = sdf.parse(checkInDateStr);
      checkInDateStr = sdfSQL.format(checkInDate);

      checkOutDate = sdf.parse(checkOutDateStr);
      checkOutDateStr = sdfSQL.format(checkOutDate);
    } catch (ParseException e) {
      e.printStackTrace();
    }

    String query =
        "where città like '"
            + city
            + "' AND "
            + "data_inizio < '"
            + checkOutDateStr
            + " 00:00:00' AND "
            + "data_finale > '"
            + checkInDateStr
            + " 00:00:00'";
    DAO dao = PernottamentoDaoHibernate.instance();
    DBManager.initHibernate();
    pernottamentoList = (List<PernottamentoEntity>) dao.getByCriteria(query);
    DBManager.shutdown();

    return pernottamentoList;
  }
  public static PernottamentoEntity getHotelById(String id) {

    List<PernottamentoEntity> pernottamentoList;

    String query = "where id =" + id + "'";
    DAO dao = PernottamentoDaoHibernate.instance();
    DBManager.initHibernate();
    pernottamentoList = (List<PernottamentoEntity>) dao.getByCriteria(query);
    DBManager.shutdown();

    return pernottamentoList.get(0);
  }
  public static List<PernottamentoEntity> searchByCity(String city) {

    List<PernottamentoEntity> pernottamentoList;

    String query = "where città like '" + city + "'";
    DAO dao = PernottamentoDaoHibernate.instance();
    DBManager.initHibernate();
    pernottamentoList = (List<PernottamentoEntity>) dao.getByCriteria(query);
    DBManager.shutdown();

    return pernottamentoList;
  }
  @Override
  public synchronized List<PernottamentoEntity> getAll() {
    Session session = DBManager.getSession();

    List<PernottamentoEntity> pernottamentoEntities =
        session.createQuery("from PernottamentoEntity").list();
    session.close();
    return pernottamentoEntities;
  }
  @Override
  public synchronized void update(AbstractEntity entity) {

    PernottamentoEntity pernottamentoEntity = (PernottamentoEntity) entity;

    Session session = DBManager.getSession();

    session.beginTransaction();
    session.update(pernottamentoEntity);
    session.getTransaction().commit();
    session.close();
  }
  @Override
  public synchronized List<PernottamentoEntity> getByQuery(String query) {
    Session session = DBManager.getSession();

    List<PernottamentoEntity> pernottamentoEntities = session.createQuery(query).list();
    session.close();
    if (pernottamentoEntities.isEmpty()) {
      return null;
    } else {
      return pernottamentoEntities;
    }
  }
  @Override
  public synchronized int store(AbstractEntity entity) {

    PernottamentoEntity pernottamentoEntity = (PernottamentoEntity) entity;

    Session session = DBManager.getSession();

    session.beginTransaction();
    session.save(pernottamentoEntity);
    session.getTransaction().commit();
    session.close();

    return pernottamentoEntity.getId();
  }
  @Override
  public synchronized PernottamentoEntity getById(int id) {
    Session session = DBManager.getSession();

    PernottamentoEntity pernottamentoEntity =
        (PernottamentoEntity)
            session.createQuery("from PernottamentoEntity where id = " + id).list().get(0);
    session.close();
    if (pernottamentoEntity == null) {
      return null;
    } else {
      return pernottamentoEntity;
    }
  }