[英]hibernate not saving the data to database
@Override
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException {
Session s = NewHibernateUtil.getSessionFactory().openSession();
Employ e = new Employ();
e.setName("JoisCreaations");
e.setId(2);
Transaction t = s.beginTransaction();
try {
t.begin();
s.save(e);
t.commit();
}
catch(Exception ss) {
t.rollback();
}
finally {
s.close();
}
PrintWriter out = res.getWriter();
out.println("SucesfullyAdded");
}
這是我的代碼。 有人可以告訴我為什么它不保存數據!!! 沒有錯誤! 一切都很好
我什至設置了配置文件並正確映射了所有內容
嗨蘇曼思
試試這個代碼。 我希望這對你有用。
@Override
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException{
SessionFactory sf = HibernateUtil.getSessionFactory();
org.hibernate.Session ss = sf.openSession();
Transaction tx = ss.beginTransaction();
try {
Employ e = new Employ();
e.setName("JoisCreaations");
e.setId(2);
ss.save(e);
tx.commit();
} catch (Exception ee) {
tx.rollback();
} finally {
ss.close();
}
PrintWriter out = res.getWriter();
out.println("SucesfullyAdded");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.