@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Configuration cfg = new Configuration();
		cfg.configure();
		ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
		SessionFactory sf = cfg.buildSessionFactory(sr);
		Session ss = sf.openSession();

		Continent northamerica = new Continent("North America", 550_000_000);
		Continent africa = new Continent("Africa", 1_100_000_000);

		Region centralamerica = new Region("Central America", 200_000_000);
		Region caribbean = new Region("Caribbean", 10_000_000);
		Region westafrica = new Region("West Africa",200_000_000);
		Region northafrica = new Region("North Africa",200_000_000);

		Collection<Region> alist = new ArrayList<Region>();
		Collection<Region> nlist = new ArrayList<Region>();

		nlist.add(caribbean);
		nlist.add(centralamerica);
		alist.add(westafrica);
		alist.add(northafrica);
		
		northamerica.setRegions(nlist);
		africa.setRegions(alist);
		
		ss.beginTransaction();
		ss.save(northamerica);
		ss.save(africa);
		ss.save(centralamerica);
		ss.save(caribbean);
		ss.save(westafrica);
		ss.save(northafrica);
		ss.getTransaction().commit();

		SQLQuery query = ss.createSQLQuery("SELECT POPULATION FROM CONTINENT where rownum=1");
		query.addScalar("POPULATION");
		List<BigDecimal> populations = query.list(); 
		System.out.println(populations);
		for (BigDecimal population : populations) {
			System.out.println(population);
		}
		
		query = ss.createSQLQuery("SELECT CONTINENT_NAME, POPULATION FROM CONTINENT");
		query.addScalar("CONTINENT_NAME");
		query.addScalar("POPULATION");
		List<Object[]> objectArrayList = query.list(); 
		System.out.println(objectArrayList);
		for (Object[] objectArray : objectArrayList) {
			System.out.print(objectArray + "--> ");
			for (Object object : objectArray) {
				System.out.print(object.getClass().getName() + ": ");
				System.out.print(object + ". ");
			}
			System.out.println();
		}


		query = ss.createSQLQuery("SELECT * FROM CONTINENT");
		query.addEntity(Continent.class);
		List<Continent> continentList = query.list(); 
		System.out.println(continentList);
		for (Continent continent : continentList) {
			System.out.println(continent);
		}

		query = ss.createSQLQuery("SELECT DUMMY FROM DUAL");
		query.addScalar("DUMMY");
		List<String> stringList = query.list(); 
		System.out.println(stringList);
		for (String string : stringList) {
			System.out.println(string);
		}
		
		String regionName = "Caribbean";
		Query hqlQuery = ss.createQuery("select population from Region region where region.regionName = :name");
		hqlQuery.setString("name", regionName);
		Long population = (Long) hqlQuery.uniqueResult();
		System.out.println("The population of " + regionName + " is " + population + ".");
		
		ss.close();
		System.exit(0);
	}