title: capture final SQL query generated by hibernate JPA in JBoss AS 7
body: <p>I have been trying really hard to capture the exact SQL of a really complicated JPA query in my project for the purpose of optimization but so far i am unable to do so. I have tried the following ways:</p>
  
  <p>1) Tried enabling hibernate logs via logback by putting following in my logback.xml and enabling show_SQL</p>
  
  <pre><code>    &lt;logger name="org.hibernate.type" level="ALL" /&gt;
   &lt;logger name="org.hibernate" level="TRACE"&gt;
      &lt;appender-ref ref="fdpAdminAppender" /&gt;
   &lt;/logger&gt;
  </code></pre>
  
  <p>2) Tried using P6spy-2 drivers with Jboss AS7 and postgres but just couldn't make it working. It gives the following exception.</p>
  
  <pre><code>com.p6spy.engine.spy.P6SpyDriver cannot be cast to javax.sql.XADataSource
  </code></pre>
  
  <p>3) Enabled inbuild Datasource spy in JBoss AS 7 and it did work. But the logs show way too much data all of which is useless to me as they again append the values as '?'. Even if i can get a way to get complete SQL statements here, my problem will be solved.</p>
  
  <p>So far i have succeeded with step 3 only but either i am missing out something or it works this way, either case my actual purpose is not resolved. So please somebody help me get the actual SQL query from JPA. I am not concerned about how i get it, i just need to get it. 
  I have experienced the need to verify the actual SQL generated by JPA with values so many times during development. It is strange why there is no standard way to do that.</p>