SRy SRy - 1 year ago 137
SQL Question

How can I update specific field in database by HibernateTemplate

I want to Update a specific field in the database

table by using HibernateTemplate.I am trying to do like this but this not working.

public void updateDate(int Id,Date recievedDate){
String qureyString="update Persons set recievedDate=? where Id=? ";
getHibernateTemplate().update(qureyString, new Object[]{Id,recievedDate});

I am getting
UnkownEntity Exception
when I run this query.Can I do Update of a specific field at all by using HibernateTemplate? Is there any other alternate to do Speicific field update?

Answer Source

update method in getHibernateTemplate does not allow hql query to execute. It only allows hibernate entity object.

See link hibernate template update method

In your case Hibernate tries to resolve update Persons set recievedDate=? where Id=? as an entity.


Query q = s.createQuery("update Persons set recievedDate=:recievedDate where Id=:Id");
q.setString("recievedDate", "some date");
q.setString("Id", "54");

Hope its clear.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download