Option 1 :
StringBuilder idsAsString = new StringBuilder();
for(Long id: ids){
idsAsString.append(id);
idsAsString.append(",");
}
idsAsString.setLength(idsAsString.length() -1);
Query q = session.createQuery(String.format(
"select mf.id from AbstractMasterField mf where mf.id in (%s) and mf.id in (select bmf.baseMasterField.id from AbstractMasterField bmf where bmf.baseMasterField is not null)",
idsAsString.toString()));
return q.list();
Option 2:
Query q = session.createQuery("select mf.id from AbstractMasterField mf where mf.id in (:idList)");// and mf.id in (select bmf.baseMasterField.id from AbstractMasterField bmf where bmf.baseMasterField is not null)");
q.setParameterList("idList", ids, new LongType());
return q.list();
In given options, only (1) works. Option 2 doesn't work.
Both options are doing same thing.
Does anybody know why option 2 dont work?
|