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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria to SQL" Watch "Criteria to SQL" New topic

Criteria to SQL

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
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.

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,

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

Joined: May 05, 2010
Posts: 75
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

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

I agree. Here's the link:
subject: Criteria to SQL
It's not a secret anymore!