I am building a query using the JPA's CriteriaBuilder
to call the SQL Server exist
function to find data based on an XML field and it is failing to run due to a The argument 1 of the XML data type method "exist" must be a string literal.
error.
I traced the SQL generated and get the same error when I try the query in SQL Server Management Studio. I've simplified the SQL to the following for reference
declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,
N'@P0 varchar(8000)',
N'select id, name from mytable where xmlfield.exist(@P0)=1 order by id desc',
'true()'
select @p1
The interesting thing is when I try the query by itself, it runs fine and returns the results.
select id, name from mytable where xmlfield.exist('true()')=1 order by id desc;
Any thoughts on why the generated parameterized SQL statement generated does not work?