[英]Update with Join hibernate (HQL)
I'm on trouble with an hql problem. 我遇到了HQL问题。
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和Widhdrawal。
Client : idClient, name ... 客户:idClient,名称...
Widhdrawal : idWidh, cost, and the idClient (foreign key) Widhdrawal:idWidh,cost和idClient(外键)
Now if i would update the client, under the condition of (idClient = 5 for example), i can't. 现在,如果我要更新客户端,则在(例如idClient = 5)的条件下,我不能。
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)"; 字符串hql =“ UPDATE Widhdrawal W set W.cost =:salary” +“其中W.id_client =(从客户端选择id_client,其中id_client =:employee_id)”;
Widhdrawal and client is POJO class name. Widhdrawal和client是POJO类名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.