0

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

1
  • hi could anybody plz help me out!! Commented Oct 24, 2013 at 12:06

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

6 Comments

Because the above syntax is for getting a list from a query as in select * from employees
here I could not understand what is the table name
Now the query is executing fine but the data is not updating in table
In that case you probably need a transaction which will need commiting as in tx = session.beginTransaction();
OK - does it work? You may want to wrap the code in a try/catch and only do the commit if no exceptions otherwise rollback
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.