hibernate - Delete query with MAX in HQL -


i have tried use hql strings delete, can not find out problem is. last try was:

    final string deletestring = "delete foo l l.id < (max(id) l)";      final query query = this.getentitymanager().createquery(deletestring);      final int deleted = query.executeupdate(); 

i getting this:

org.hibernate.hql.ast.querysyntaxexception: unexpected token: near line 1, column 73 [delete eu.unicorn.ctds.entity.foo l l.id < (max(id) l) 

where problem?

missing select before max. try

final string deletestring = "delete foo l l.id < ( select max(id) l)"; 

after correcting query above, error while execution saying "you can't specify target table 'foo' update/delete in clause" means cannot delete row in foo while selecting max same table foo. have 2 queries. first query select max id , use id in delete query.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -