I tried a lot to update my table with hql, but I did not find a solution, I also searched the Internet, I am new to java and hibernate, help me find a solution.
my code is written below.
session.getTransaction().begin(); Query query = session.createQuery("update DocDetail set DocName = :docname" + " where Id = :docId"); query.setParameter("docname", "Jack"); query.setParameter("docId", 3); int result = query.executeUpdate(); session.getTransaction().commit();
but I got the following error.
Exception in thread "AWT-EventQueue-0" org.hibernate.QueryException: query must begin with SELECT or FROM: update [update clinic.entity.DocDetail set DocName = :studentName where Id = :studentId] at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:106) at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:131) at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:51)
source share