package com.javahonk;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.javahonk.bean.Address;

public class HibernateAnnotationTest {
	
	public static void main(String[] args) {

		SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.openSession();
        session.beginTransaction();

        Address address=new Address();
		address.setSteetName("John st."); 
		address.setLocation("NY");
		address.setCity("NY");
		address.setZip("123456");
		address.setState("NY");
		
        session.save(address); 

        List<Address> address3 = session.createQuery("from Address")
        		.list();
        for (Address address2 : address3) {
            System.out.println("Address table data:");
            System.out.println("Stree Name: "+address2.getSteetName()
            		+" Location: "+address2.getLocation()+" City: "
            		+address2.getCity()+" State: "+address2.getState()
            		+" Zip: "+address2.getZip());
            
        }

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

	}
}
