本文介绍了通过加入休眠(HQL)进行更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想编写一个查询,更新一个属性,并且基于另一个表上的值。

这是我的例子,我有这两个表:Client和Widhdrawal。

客户端:idClient,名称...

提取:idWidh,成本和idClient(外键)

现在,如果我在(idClient = 5例如)条件下更新客户端,我不能。



我试过了,但徒劳无功:

 字符串hql =UPDATE Widhdrawal W set W.cost =:salary+ 
其中W.Client.id_client =:employee_id) ;

查询查询= session.createQuery(hql);
query.setParameter(salary,1000);
query.setParameter(employee_id,5);
int result = query.executeUpdate();

我希望有人可以提供一些建议,谢谢。




字符串hql =UPDATE Widhdrawal W set W.cost =:salary +
其中,W.id_client =(从客户端选择id_client,其中id_client =:employee_id);

提款和客户端是POJO类名称 p>

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 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.

这篇关于通过加入休眠(HQL)进行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:22