Kawu Kawu - 1 month ago 19
Java Question

JPA: how do you get/print the JPQL query string behind a (typed) query after parameters have been set?

How do you get/print the JPQL query string behind a (typed) query, that is after parameters have been set? (e.g. for debugging purposes)

A simple

toString()
doesn't seem to do the trick...

Thanks

Answer

There is no such thing as "the final JPQL that ultimately gets translated to the final SQL". How a JPA implementation generates the SQL is down to it, and parameters in general will never be substituted into any String. SQL is generated from expression trees etc not a String. If you want param values inserting in then do it yourself since it only makes sense to you