Question

I have this query that I would like to translate in Criteria Hibernate:

UPDATE Patient SET HourOut = ? WHERE IDQueue = ? AND TicketNumber = ? AND DATE_FORMAT(DATE(LastVisitDate), '%Y-%m-%d') = ?;

I understand the way to update an object when it's id is known but I can't figure out how to do it with the kind of where i have here.

Was it helpful?

Solution

You can use a Example.

Patient example = new Patient();
example.setLastVisitDate(date);
example.setIDQueue(idq);
example.setTicketNumber(tnbr);

matchesDate = session.createCriteria(Patient.class)
                 .add(Example.create(example)).list();
for(Patient patient : matchesDate){
    Transaction t=session.beginTransaction();
    patient.setHourOut(outH);
    session.saveOrUpdate(patient);
    t.commit();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top