-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Get SQL query after executing criteria.list() ?
PostPosted: Wed Sep 27, 2006 8:04 am 
Newbie

Joined: Wed Sep 27, 2006 7:56 am
Posts: 1
Hibernate version:3.1.3 / Java 1.5


Hi,

is it possible to get the native sql query behind a criteria ?

I use Criteria API to filter a list of pojo. After filtering, I need

to export data to Excel with Jasper Reports. I want to retrieve

the native SQL to associate it with my report ... I tried to use

the statistics but the String[] returned with getQueries() is always

empty :

HibernateUtils.getSessionFactory().getStatistics().setStatisticsEnabled(true);

this.liste = criteria.list();

Statistics stats = HibernateUtils.getSessionFactory().getStatistics();
HibernateUtils.getSessionFactory().getStatistics().setStatisticsEnabled(false);
String [] queries = stats.getQueries();
...

Any idea ?

Thanks a lot,

Bruno.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 6:06 am 
Newbie

Joined: Tue Aug 29, 2006 10:56 am
Posts: 15
Hello,

I have the same problem.

See class org.hibernate.loader.Loader.java

Code:
/**
* Identifies the query for statistics reporting, if null,
* no statistics will be reported
*/
protected String getQueryIdentifier() {
      return null;
}


This method is invoked.

Replace the line:
Code:
return null;
with
Code:
getSQLString();
.

I am testing just now this workaround. The solution has effects to the Statistics API regarding query cache.

Let me know if you get an alternate solution or if you have problems with the workaround.

mba


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 6:24 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Create the session with an interceptor and use

org.hibernate.Interceptor.onPrepareStatement(String sql);

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.