hql
2010-11-24 272 views 0 likes 
0
執行上述查詢時,我收到以下錯誤
Query query = session.createQuery("Update Contact set firstname = 'sdf' where firstname= 'Deepak'"); 
int result = query.executeUpate(); 

Hibernate查詢語言更新錯誤

expecting DOT, found '=' near line 1, column 30 
[Update Contact set firstname = 'sdf' where firstname= 'Deepak'] 

是否有人可以幫助我這個

回答

2

你正在寫在SQL查詢不, HQL。在HQL批量更新會是這個樣子:

String query = "update Contact c set c.firstname = :newName where c.name = :oldName"; 
int result = s.createQuery(query) 
     .setString("newName", "sdf") 
     .setString("oldName", "Deepak") 
     .executeUpdate(); 

但是,除非有大量的與姓迪帕克行的,這是錯誤的做法。如果你只是更新一個對象,最好a)做一個返回這個對象的查詢,並且b)更新對象只需myobject.firstname = "sdf";

相關問題