Reputation: 81
hi am very new to hibernate and could anybody plz help me out how to use update query to upadte the record of the table ...i am using like this in dao class
Session ses = HibernateUtil.getSessionFactory().openSession();
Transaction tx = ses.beginTransaction();
Query q = ses.createQuery("from RegisterPojo where email =:email");
q.setParameter("email", bean.getEmail());
RegisterPojo pojo = (RegisterPojo) q.list().get(0);
pojo.setUname(bean.getUname());
ses.update(pojo);
tx.commit();
ses.flush();
ses.close();
Hi i have edited my code from this am getting exception as, Could not execute JDBC batch update
thanks in advance
Upvotes: 0
Views: 201
Reputation: 44813
You need to call update
on the hibernate session
Observe the following example
Query q = session.createQuery("from RegisterPojo where email =:email");
q.setParameter("email", "[email protected]");
RegisterPojo pojo= (RegisterPojo)q.list().get(0);
pojo.setName("Fred");
session.update(pojo);
Upvotes: 1