You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Daniel Migowski <dm...@ikoffice.de> on 2007/07/05 17:05:58 UTC

How to get the compiled JPQL query string as SQL

Hi OpenJPA users,

Is there a wy to get the SQL the would be executed, if I execute a 
JPQL-query? The method (OpenJPAQuery)myQuery).getDatastoreActions() 
always returns an empty String array.

With best regards,
Daniel Migowski

Re: How to get the compiled JPQL query string as SQL

Posted by Patrick Linskey <pl...@gmail.com>.
That was a bug (OPENJPA-278). Sorry about that. It's fixed now.

-Patrick

On 7/5/07, Daniel Migowski <dm...@ikoffice.de> wrote:
>
>  Hello Patrick,
>
>  I tried to compile, too, but this is what my code delivered:
>
>          Query q = em.createQuery("select currency.name, currency.isoCode3
> "+
>                                   "from Currency
> currency");
>
>          for (Object[] o :
> (List<Object[]>)q.getResultList()) {
>              System.out.println(o[0] + " - " + o[1]);
>  ... prints all the names and isocodes ...
>          }
>
>          OpenJPAQuery q2 = (OpenJPAQuery)q;
>          System.out.println(q2.getQueryString());
>  ... prints "select currency.name, currency.isoCode3 from Currency currency"
> ...
>
>          q2 = q2.compile();
>
>          System.out.println(q2.getLanguage());
>  ... prints something about JPQL ...
>
>             String[] actions = q2.getDataStoreActions(null);
>          for( String s : actions ) {
>              System.out.println(s);
>          }
>  ... prints nothing, since the array has the size 0 ...
>
>  Just looking at the log does not help, because i need the query to modify
> it and work around the but in my previous post :))
>
>  Greetings,
>  Daniel Migowski
>
>
>
>  Patrick Linskey schrieb:
> If you're just looking to get logging data, you can just set the
>  'openjpa.Log' property to 'SQL=TRACE'.
>
>  However, getDatastoreActions() should return the strings. Can you post
>  the code corresponding code snippet? Also, what happens if you do
>  ((OpenJPAQuery) myQuery).compile() before trying to get the actions?
>  (I don't have the source in front of me right now, so that's a bit of
>  a shot in the dark.)
>
>  -Patrick
>
>  On 7/5/07, Daniel Migowski <dm...@ikoffice.de> wrote:
>
> Hi OpenJPA users,
>
>  Is there a wy to get the SQL the would be executed, if I execute a
>  JPQL-query? The method
> (OpenJPAQuery)myQuery).getDatastoreActions()
>  always returns an empty String array.
>
>  With best regards,
>  Daniel Migowski
>
>
>
>
>
>
> --
>  |¯¯|¯¯| IKOffice GmbH Daniel Migowski
>  | | |/| Mail: dmigowski@ikoffice.de
>  | | // | Nordstr. 10 Tel.: +49 (441) 21 98 89 52
>  | | \\ | 26135 Oldenburg Fax.: +49 (441) 21 98 89 55
>  |__|__|\| http://www.ikoffice.de Mob.: +49 (176) 22 31 20 76
>
>  Geschäftsführer: Ingo Kuhlmann, Daniel Migowski
>  Amtsgericht Oldenburg, HRB 201467
>


-- 
Patrick Linskey
202 669 5907

Re: How to get the compiled JPQL query string as SQL

Posted by Patrick Linskey <pl...@gmail.com>.
If you're just looking to get logging data, you can just set the
'openjpa.Log' property to 'SQL=TRACE'.

However, getDatastoreActions() should return the strings. Can you post
the code corresponding code snippet? Also, what happens if you do
((OpenJPAQuery) myQuery).compile() before trying to get the actions?
(I don't have the source in front of me right now, so that's a bit of
a shot in the dark.)

-Patrick

On 7/5/07, Daniel Migowski <dm...@ikoffice.de> wrote:
> Hi OpenJPA users,
>
> Is there a wy to get the SQL the would be executed, if I execute a
> JPQL-query? The method (OpenJPAQuery)myQuery).getDatastoreActions()
> always returns an empty String array.
>
> With best regards,
> Daniel Migowski
>


-- 
Patrick Linskey
202 669 5907