I could fix my similar issue by adding
Code:
OPTION (RECOMPILE)
to my query.
See
https://msdn.microsoft.com/en-us/library/ms181714.aspxI sneak them into the Query by getting the CriteriaImpl via reflection and calling .setQueryHint("RECOMPILE")
and the QueryHint is later added to the SQL String via an extended jTDS Driver that implements the
Code:
public String getQueryHintString(String query, List<String> hints) {
StringBuilder out = new StringBuilder(query);
for(String hint: hints) {
out.append("\n ").append("OPTION (").append(hint).append(")");
}
return out.toString();
}
Hope it helps someone.