I am trying to run an update request that will look like this: sql:
update studentMaster set sess_status = 'G' where ACADEM_YEAR = COURSE_YEAR;
I am trying to recreate a query using Criteria as follows:
public void updateSessionStatus() { Session sess = factory.openSession(); Transaction tx = null; try { tx = sess.beginTransaction(); Criteria crit = sess.createCriteria(CollegeStudentsMaster.class); crit.add(Restrictions.eqProperty("academicYear", "courseYears")); CollegeStudentsMaster e = (CollegeStudentsMaster) crit.uniqueResult(); e.setSessionStatus("G"); sess.saveOrUpdate(e); tx.commit(); } catch (HibernateException asd) { if (tx != null) { tx.rollback(); } log.debug(asd.getMessage()); } finally { sess.close(); } }
This does not work, because there are many lines that satisfy these criteria, my unique result is the problem here, I think. How can I convert this to an update for all rows that match the criteria. I donβt want to use the HQL query, I rather do it using criteria.
java hibernate persistence
ErrorNotFoundException
source share