openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Migowski <dmigow...@ikoffice.de>
Subject Re: How to get the compiled JPQL query string as SQL
Date Thu, 05 Jul 2007 19:07:46 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Patrick,<br>
<br>
I tried to compile, too, but this is what my code delivered:<br>
<tt><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Query q = em.createQuery("select
currency.name,
currency.isoCode3 "+<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"from Currency currency");<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (Object[] o : (List&lt;Object[]&gt;)q.getResultList())
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(o[0] + " - " + o[1]);<br>
<font color="#ff0000">... prints all the names and isocodes ...</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OpenJPAQuery q2 = (OpenJPAQuery)q;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(q2.getQueryString());<br>
</tt><tt><font color="#ff0000">... prints "select currency.name,
currency.isoCode3 from Currency currency" ...</font><br>
</tt><br>
<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q2 = q2.compile();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(q2.getLanguage());<br>
</tt><tt><font color="#ff0000">... prints something about JPQL ...<br>
<br>
</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
String[] actions =
q2.getDataStoreActions(null);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( String s : actions
) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
System.out.println(s);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
</tt><tt><font color="#ff0000">... prints nothing, since the array has
the size 0 ...<br>
</font></tt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</tt><br>
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 :))<br>
<br>
Greetings,<br>
Daniel Migowski<br>
<br>
<br>
<br>
Patrick Linskey schrieb:
<blockquote
 cite="mid7262f25e0707050826s2a9dfc4dh2d0e39d8661e6c51@mail.gmail.com"
 type="cite">If you're just looking to get logging data, you can just
set the
  <br>
'openjpa.Log' property to 'SQL=TRACE'.
  <br>
  <br>
However, getDatastoreActions() should return the strings. Can you post
  <br>
the code corresponding code snippet? Also, what happens if you do
  <br>
((OpenJPAQuery) myQuery).compile() before trying to get the actions?
  <br>
(I don't have the source in front of me right now, so that's a bit of
  <br>
a shot in the dark.)
  <br>
  <br>
-Patrick
  <br>
  <br>
On 7/5/07, Daniel Migowski <a class="moz-txt-link-rfc2396E" href="mailto:dmigowski@ikoffice.de">&lt;dmigowski@ikoffice.de&gt;</a>
wrote:
  <br>
  <blockquote type="cite">Hi OpenJPA users,
    <br>
    <br>
Is there a wy to get the SQL the would be executed, if I execute a
    <br>
JPQL-query? The method (OpenJPAQuery)myQuery).getDatastoreActions()
    <br>
always returns an empty String array.
    <br>
    <br>
With best regards,
    <br>
Daniel Migowski
    <br>
    <br>
  </blockquote>
  <br>
  <br>
</blockquote>
<br>
<br>
<div class="moz-signature">-- <br>
<pre> |&macr;&macr;|&macr;&macr;|    IKOffice GmbH             Daniel
Migowski
 |  |  |/|                            Mail: <a
 href="mailto:dmigowski@ikoffice.de">dmigowski@ikoffice.de</a>
 |  | // |  Nordstr. 10               Tel.: +49 (441) 21 98 89 52
 |  | \\ |  26135 Oldenburg           Fax.: +49 (441) 21 98 89 55
 |__|__|\|  <a href="http://www.ikoffice.de">http://www.ikoffice.de</a>    Mob.:
+49 (176) 22 31 20 76
 
            Gesch&auml;ftsf&uuml;hrer: Ingo Kuhlmann, Daniel Migowski
            Amtsgericht Oldenburg, HRB 201467</pre>
</div>
</body>
</html>

Mime
View raw message