You are on page 1of 1

package com.

test;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.entity.Pet;
import com.utility.Utility;

public class SaveObject {


public static int save(Pet pet) {
//get the session Object
Session ses = Utility.getSession();
Transaction tx = null;
Integer count = 0;
try(ses){
//brgin the transaction
tx = ses.beginTransaction();
//save the object
count = (Integer) ses.save(pet);
//commit the trasaction
tx.commit();
}catch(HibernateException he) {
he.printStackTrace();
tx.rollback();
}catch(Exception e) {
e.printStackTrace();
tx.rollback();
}
return count;
}
}

You might also like