October 22, 2024
Chicago 12, Melborne City, USA
java

How can I create a CriteriaUpdate query where I select the 'id' column if a method its true which changes another column in its table?


I have a Java 8 project. I have a Server class containing:
Long id
string name
string ipAddress
String status

Its an entity to a SQL database. I want to run a criteriaUpdate query that updates my table based on the method outcome. If ‘id’ 1 cant be pinged, how do I change the ‘status’ column without changing all the other ‘id’ columns to.

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaUpdate<ServersDao> cu = cb.createCriteriaUpdate(ServersDao.class);
Root<ServersDao> root = cu.from(ServersDao.class);
cu.set("status", "SERVER_UP");
cu.where(cb.equal(root.get("status", "SERVER_DOWN")));

The problem I have is this changes all my rows in my column to either SERVER_UP or SERVER_DOWN. I need thsi to be based on the relative ‘id’ field, not for all my other id’s.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video