How to convert nested SQL to HQL

前端 未结 4 1575
-上瘾入骨i
-上瘾入骨i 2021-01-02 01:52

I am new to the Hibernate and HQL. I want to write an update query in HQL, whose SQL equivalent is as follows:

update patient set 
      `last_name` = \"new_         


        
4条回答
  •  悲哀的现实
    2021-01-02 02:04

    There is a significant difference between executing update with select and actually fetching the records to the client, updating them and posting them back:

    UPDATE x SET a=:a WHERE b in (SELECT ...) 
    

    works in the database, no data is transferred to the client.

    list=CreateCriteria().add(Restriction).list();
    

    brings all the records to be updated to the client, updates them, then posts them back to the database, probably with one UPDATE per record.

    Using UPDATE is much, much faster than using criteria (think thousands of times).

提交回复
热议问题