views:

62

answers:

2
+2  Q: 

JPA Query toString

Hello SO,
I have a JPA Query I am executing on the Google App-Engine datastore.
I am building the query using parameters.
After all parameters have been inputted, I wish to view the Query String.

That is, I wish to view the actual query being executed by the datastore.
Is that even possible? It would really help me in debugging.

To SOLVE the question, assume the following query:

Query query=EM.createQuery("SELECT FROM "
+MyClass.class.getName()+" C WHERE C.field = :arg1");
query.setParameter("arg1", someParam);

if System.out.println(SomeObj) prints 'SELECT FROM MyClass C WHERE C.field = 17' then the question is solved.

David

+1  A: 

That is, I wish to view the actual query being executed by the datastore.

Enabling DEBUG for the DataNucleus.Datastore log category should do it. Check the DataNucleus Logging documentation.

Pascal Thivent
A: 

In current DataNucleus you can just call toString() on the JPA Query object to see the single-string form (without parameter substitution). The actual query invoked on the datastore depends on the datastore (obviously), being SQL in the case of RDBMS, and something else in the case of BigTable.

DataNucleus