1
我一直在做一個簡單的程序中使用Hibernate框架如下保存在MySQL的僱員的詳細信息在數據庫中插入製作...使用Hibernate未做事務實例
public class Manifest {
Session session;
public static void main(String[] args) {
Employee employee = new Employee("varun");
new Manifest().addEmployee(employee);
}
/* Method to CREATE an employee in the database */
public void addEmployee(Employee employee){
Integer employeeID=null;
SessionGenerator sessionGenerator = new SessionGenerator();
try{
session = sessionGenerator.getSessionToDb();
employeeID = (Integer) session.save(employee);
System.out.println(employeeId);
}catch (HibernateException e) {
e.printStackTrace();
}finally {
session.close();
}
}
}
我知道的事實,我應該使用session.beginTransaction();
& tx.commit()
但我的問題是,爲什麼在我的情況下沒有引發異常,它在控制檯上打印employeeId,但沒有在數據庫中進行任何輸入..背後的原因是什麼?