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
Post a Comment