I'm on trouble with an hql problem.
I would like to write a query, that updates an attribut, and that's based on a value on another table.
This is my example, I have those two tables : Client and Widhdrawal.
Client : idClient, name ...
Widhdrawal : idWidh, cost, and the idClient (foreign key)
Now if i would update the client, under the condition of (idClient = 5 for example), i can't.
I tried this, but in vain :
String hql = "UPDATE Widhdrawal W set W.cost = :salary " +
"where W.Client.id_client = :employee_id)";
Query query = session.createQuery(hql);
query.setParameter("salary", 1000);
query.setParameter("employee_id", 5);
int result = query.executeUpdate();
I hope that someone can have some advices, thank you.
Try this:
String hql = "UPDATE Widhdrawal W set W.cost = :salary " +
"where W.idClient = :employee_id)";
Thank you, i found the solution. I hope that this can help other people ... This problem is du to lowerCase.
String hql = "UPDATE Widhdrawal W set W.cost= :newCost " +
"where W.client.id_client = :id_cl";
Query query = session.createQuery(hql);
Try this way --
String hql = "UPDATE Widhdrawal W set W.cost = :salary " + "where W.id_client =(select id_client from client where id_client = :employee_id)";
Widhdrawal and client is POJO class name.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.