package example;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class MainClient {

	public static void main(String[] args) {
		Configuration cfg = new Configuration();  // First configure.
		cfg.configure();
		SessionFactory factory = cfg.buildSessionFactory();  // Get a factory from cfg.
		Session session = factory.openSession();  // Open a session from the factory.
		
		Payment p = new Payment();
		p.setAmount(10000);
	//	p.setPayementID(1);  // If the ID is auto-incrememted, we do not need to set it.
		Credit c = new Credit();
		c.setAmount(20000);
		c.setCreditType("Visa"); 
		Debit d = new Debit();
		d.setAmount(30000);
		d.setDebitType("Boa");
		
		Transaction t = session.beginTransaction();  // Need a transaction to commit.
		session.save(p);  // Save the three payments into session cache.
		session.save(c);
		session.save(d);
		t.commit();  // Commit the change into database.
		session.close();
		factory.close();
	}
}
