private static void load() {
   System.out.println("==============LOAD=================");
   Session session = hs.getSessionFactory(false).openSession();
   session.beginTransaction();
   Region region = (Region) session.load(Region.class, id);
   System.out.println("region = " + region);
   session.getTransaction().commit();
   session.close();
 }
  private static void delete() {
    System.out.println("==============DELETE=================");
    Session session = hs.getSessionFactory(false).openSession();
    session.beginTransaction();
    City city = (City) session.load(City.class, id);

    session.delete(city);

    session.getTransaction().commit();
    session.close();
  }
 private static void createAutocommit() {
   System.out.println("==============AUTOCOMMIT=================");
   // Create hibernate session
   Session session = hs.getSessionFactory(true).openSession();
   // create object
   Region region = new Region("HMAO");
   // save object
   id = session.save(region);
   System.out.println("id = " + id);
   session.flush();
   session.close();
 }
  private static void update() {
    System.out.println("==============UPDATE=================");
    Session session = hs.getSessionFactory(false).openSession();
    session.beginTransaction();
    City city = (City) session.load(City.class, id);
    city.setCityName("nefteugansk");
    session.saveOrUpdate(city);
    System.out.println("city = " + city);

    session.getTransaction().commit();
    session.close();
  }
 private static void create() {
   System.out.println("==============CREATE=================");
   // Create hibernate session
   Session session = hs.getSessionFactory(false).openSession();
   // begin transaction
   session.beginTransaction();
   // create object
   Region region = new Region("Saint-Petersburg!");
   // save object
   session.save(region);
   session.getTransaction().commit();
   session.close();
 }
  public static void main(String[] args) {
    HibernateSimple hs = new HibernateSimple();

    Session s = hs.getSessionFactory().openSession();
    s.beginTransaction();

    Query q = s.createQuery("from Region");
    List<Region> regionList = q.list();

    for (Region r : regionList) {
      System.out.println("Region name:" + r);
      // System.out.println("Cities size:" + r.getCityList().size());
    }

    System.out.println("======================================");
    s.flush();
    s.getTransaction().commit();
    s.close();

    AnotherClass.printAgain(
        regionList); // uncomment this and comment this System.out.println("Cities size:" +
                     // r.getCityList().size());
  }
  private static void getVsLoad() {
    System.out.println("==============GET_VS_LOAD=================");
    Session session = hs.getSessionFactory(false).openSession();
    session.beginTransaction();
    Region region = (Region) session.get(Region.class, id);
    City city1 = new City();
    city1.setCityName("Surgut");
    city1.setRegion(region);
    session.save(city1);

    region = (Region) session.load(Region.class, id);
    City city2 = new City();
    city2.setCityName("Nizhnevartovsk");
    city2.setRegion(region);
    id = session.save(city2);

    session.getTransaction().commit();
    session.close();
  }