package hibernate;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class Test {
public static void main(String[] args){
try {
//the familiar sessionFactory
SessionFactory sf=new Configuration().configure().buildSessionFactory();
//get the session instance
Session session=sf.openSession();
//begin transaction
Transaction tx=session.beginTransaction();
//create a new user object
User user= new User();
//evaluate a value to the object
user.setUsername("hibernate");
user.setPassword("123");
//transfer the method sava() to save the instance to db
session.save(user);
//commit the transaction
tx.commit();
//close the session
session.close();
} catch (HibernateException e)
{
e.printStackTrace();
}
}
}