Home Tutorialhelp Comment Hi Harish, You wrap the session.save() method w

 
 

Comment

Deepak Kumar
Hi Harish, You wrap the session.save() method w,
December 9, 2006 at 11:54 PM

Hi Harish,

You wrap the session.save() method within transaction block and then commit the transaction.

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Transaction tx;
try {
tx = session.beginTransaction();
//do some work
Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);

tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
session.close();
}

After modifying the code in this way, you will be able to solve the problem.

Thanks
Deepak
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Advertisements Advertisements
 

 

 

DMCA.com