Reputation: 13
I'm attempting to cast a text to a varchar due to a previous issue I had regarding this error message:
The data types text and varchar are incompatible in the equal to operator RSS
With a quick search, I found that I need to cast the value which is text to that of a varchar. I have done so:
@Query("SELECT e FROM DeStudent e " +
"WHERE CAST(e.studentExpression as varchar) = :studentExpression" +
"AND e.deactivationTime = '9999-12-31 00:00:00.000' " +
"AND (:studentName is null OR e.name = :studentName)" +
"AND (:studentDescription is null OR e.description = :studentDescription)" +
"AND (:studentExpression is null OR e.studentExpression = :studentExpression)"
)
However I seem to be getting this error:
2020-07-08 14:42:39.947 ERROR o.h.hql.internal.ast.ErrorCounter: line 1:142: unexpected token: e
And it's not allowing me to run the application due to this modification. I'm unsure what I have done, any help? Thank you. I've tried different variations as well, such as moving the cast to the select section but it's still the same error.
Upvotes: 0
Views: 286
Reputation: 311
The error message is telling you that the issue is with the letter 'e' not being understood. Your select clause is where the issue is. You wrote SELECT e FROM DeStudent e
, which aliased the DeStudent table as 'e', but the select clause should specify columns, not just 'e'. To select everything, use *.
SELECT * FROM DeStudent e
Upvotes: 1