Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » SQL String from JPQL Query(How to get a complete SQL String from JPQL Query)
SQL String from JPQL Query [message #685893] Mon, 20 June 2011 10:34 Go to next message
Alberto  is currently offline Alberto
Messages: 7
Registered: February 2011
Junior Member
I've a JPQLquery and I want to get the sql String..
Now I'm doing in this way:

EJBQueryImpl qi = (EJBQueryImpl)jpqlQuery;
String sqlQueryString = qi.getDatabaseQuery().getSQLString();


The problem is that in the sqlQueryString the constant are replaced with ?

I've tried to get the values of the parameters navigating the expressions trees (getSelectionCriteria() and getHavingCriteria()) and I get it.. the problem is that in this way I lose the type (I can't get the difference between Strings or int..)

Do any one ever have a problem like this one?

[Updated on: Mon, 20 June 2011 11:11]

Report message to a moderator

Re: SQL String from JPQL Query [message #686068 is a reply to message #685893] Tue, 21 June 2011 11:09 Go to previous messageGo to next message
Sven Klemm is currently offline Sven Klemm
Messages: 8
Registered: June 2011
Junior Member
If you needed in runtime - i don't know yet...
... but in the log (tested with logging mode "ALL") you'll get the bindings:
----------------------------------------------------------
[EL Fine]: 2011-06-21 17:06:00.434--ClientSession(305967)--Connection(18388366)--Thread(Thread[main,5,main])--SELECT col1, col2 FROM mytable WHERE (col1 = ?)
bind => [1]
----------------------------------------------------------

persistence.xml:
----------------------------------------------------------
<property name="eclipselink.logging.file" value="output.log"/>
<!--property name="eclipselink.logging.level" value="SEVERE"/ -->
<property name="eclipselink.logging.level" value="ALL"/>
----------------------------------------------------------


So stmt = SELECT col1, col2 FROM mytable WHERE (col1 = 1)

sk

[Updated on: Tue, 21 June 2011 11:11]

Report message to a moderator

Re: SQL String from JPQL Query [message #687947 is a reply to message #686068] Thu, 23 June 2011 10:57 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

See,

http://wiki.eclipse.org/EclipseLink/FAQ/JPA#How_to_get_the_SQL_for_a_Query.3F


James : Wiki : Book : Blog : Twitter
Previous Topic:@UnionPartitioning does not seem to be using the correct connection pool
Next Topic:(no subject)
Goto Forum:
  


Current Time: Thu Jul 31 05:33:37 EDT 2014

Powered by FUDForum. Page generated in 0.02270 seconds