-->
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: statistics number of sql executed
PostPosted: Tue Mar 11, 2008 5:10 am 
Newbie

Joined: Tue Mar 11, 2008 4:49 am
Posts: 12
Hi
Inside my DAO method i have
Code:
session.get(OperationSent.class, id, forUpdate? LockMode.UPGRADE : LockMode.READ);

I would like somehow retireve number of sql commands executed against database to retrieve OperationSent object.
OperationSent entity has 3 one-to-one association and i would like to create Junit test to assert that this code produces exactly one sql...

Looking at statistics api i've seen
getQueryExecutionCount() method but it returns 0. After a few experiments i noticed the method returns number greater than 0 only for sql/hql queries.

Is it possible to retrieve number of sqls for session.get() , session.load()
using statistics??
and if not is any workaround to satisfy my test requirement ?
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 16, 2008 8:07 am 
Newbie

Joined: Sun Mar 16, 2008 5:24 am
Posts: 1
Location: Helsinki, Finland
Hello,

We have done just that (automatic developer tests asserting the number of SQL queries made by a Hibernate operation), using two techniques:

- programmatically turning show_sql=true, redirecting System.out and counting the number of lines starting with "Hibernate: " :)
- using Statistics.getPrepareStatementCount()

I think that Statistics.getPrepareStatementCount() is accurate and shows the same number as the SQLs shown with show_sql=true (you can confirm this by looking at the Hibernate source code).

For good error messages (showing the extra SQL statements right away), we have retained the kludge of System.out redirection, and I also submitted a little patch that adds collecting the SQLs to Statistics, let's hope that it makes it to a release:

http://opensource.atlassian.com/project ... e/HHH-3130

Best wishes,
Timo


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 6:14 am 
Newbie

Joined: Tue Mar 11, 2008 4:49 am
Posts: 12
thrantal wrote:
Hello,

We have done just that (automatic developer tests asserting the number of SQL queries made by a Hibernate operation), using two techniques:

- programmatically turning show_sql=true, redirecting System.out and counting the number of lines starting with "Hibernate: " :)
- using Statistics.getPrepareStatementCount()

I think that Statistics.getPrepareStatementCount() is accurate and shows the same number as the SQLs shown with show_sql=true (you can confirm this by looking at the Hibernate source code).

For good error messages (showing the extra SQL statements right away), we have retained the kludge of System.out redirection, and I also submitted a little patch that adds collecting the SQLs to Statistics, let's hope that it makes it to a release:

http://opensource.atlassian.com/project ... e/HHH-3130

Best wishes,
Timo


I wouldn't like to redirect System.Out and then parse, cause i have this kind of tricks...

Counting preparing statements seems to be ok for my case but need to check it in different scenarios.

I hope your patch will be merged to furute hibernate release, but i have no time now to take a look at it.

Anyway thanks a lot for your help


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.