public static void main(String[] args) { // Create configuration object Configuration cfg = new Configuration(); // Populate the data of the default configuration file which name // is hibernate.cfg.xml cfg.configure(); // Create SessionFactory that can be used to open a session SessionFactory factory = cfg.buildSessionFactory(); // Session is an interface between Java app and Database // Session is used to create, read, delete operations Session session = factory.openSession(); Transaction tx = session.beginTransaction(); // Create pojo Employee e1 = new Employee(); e1.setId(2); e1.setFirstName("Hello"); e1.setLastName("World"); // Save to database session.persist(e1); tx.commit(); // Close connection factory.close(); } }