How can I update specific field in database by HibernateTemplate
12,709
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.
Solution:
Query q = s.createQuery("update Persons set recievedDate=:recievedDate where Id=:Id");
q.setString("recievedDate", "some date");
q.setString("Id", "54");
q.executeUpdate();
Hope its clear.
Author by
SRy
Updated on June 04, 2022Comments
-
SRy almost 2 years
I want to update a specific field in the database
Persons
table by using HibernateTemplate. I am trying to do like this but this not working.public void updateDate(int Id,Date receivedDate) { Id = 10; receivedDate = 2012-11-12; String queryString = "update Persons set recievedDate=? where Id=? "; getHibernateTemplate().update(queryString, new Object[] { Id, receivedDate }); }
I am getting an exception "UnkownEntity" 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 specific field update?