This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Criteria to SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria to SQL" Watch "Criteria to SQL" New topic
Author

Criteria to SQL

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 69
I want to log the querys I make in a blaze servlet.

Any way to get the sql string from a criteria? I got it before but without the parameters (something like "where con1<?")

Thank you for your time.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi Alex.

It depends by the way you persistence provider log the information and the level of the log, generaly you need to add some properties to the persistence unit in the persistence.xml to log the sql generated with the parameters, for example for openjpa you need to add these properties: and for eclipselinkI hope this help you with your question.
Kind regards.
Cesar


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Also see,

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

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 69
Yeah, my post is a bit short on info...

I'm using Hibernate with annotations (I don't like hibernate mapping files)

And making querys like

The class is a subclass of org.springframework.orm.hibernate3.support.HibernateDaoSupport

Is there anyway to make a function like this... String criteriaToSQL(Criteria cr)?


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Criteria to SQL
 
Similar Threads
Help : Need to retrieve SQL Query from Criteria or HQL (SQL which is generated by Hibernate)
SQLException error: "Invalid Cursor position"
hello how mutch do i need to know to start learning this topic
Using 'Case when' in Hibernate Criteria API
SQL Injection