package com.javahonk;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.javahonk.bean.Address;
import com.javahonk.util.HibernateUtil;



public class InsertData {

	public static void main(String[] args) {		
				
		Session session = HibernateUtil.getSessionFactory().openSession();
 
        session.beginTransaction();
        Address address=new Address();
		address.setSteetName("Main St."); 
		address.setLocation("APT 55");
		address.setCity("Edison");
		address.setZip("10038");
		address.setState("NJ");		
 
        session.save(address);
        session.getTransaction().commit();
        
        Query query=session.createQuery("FROM Address");
        List list =query.list();
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			Address address1 = (Address) iterator.next();
			System.out.println("Stree Name: "+address1.getSteetName()+" Location: "+address1.getLocation()+" City: "+address1.getCity()+" State: "+address1.getState()+" Zip: "+address1.getZip());
			
		}
       
		
	}

}
