Platinum Partner
java,sql,frameworks,tips and tricks

EclipseLink: How to get the SQL translated with the arguments for a Query?

The documentation at the EclipseLink Wiki is not very helpful:

It says: β€œTo get the SQL translated with the arguments you need a DatabaseRecord with the parameter values.β€œ.

// BEGIN Snippet from the Wiki
Session session = em.unwrap(JpaEntityManager).getActiveSession();
DatabaseQuery databaseQuery =
String sqlString = databaseQuery
// END Snippet from the Wiki

But where to get the recordWithValues variable? Actually the solution is hard to find, but simple: databaseQuery.getTranslationRow()

// This does the trick...
String sqlString = databaseQuery
// ... to replace the '?' 

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ }}
{{ parent.authors[0].realName ||}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks