-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unit Testing Number of SQL Statements Generated by Hibernate
PostPosted: Thu Feb 26, 2004 10:07 am 
Beginner
Beginner

Joined: Sat Dec 06, 2003 5:38 pm
Posts: 27
Hi all,

One of my periodic chores after modifying our web application is to then run through all the pages with an eye to tuning the number of SQL statements issued by Hibernate. It is very easy to change something in the hbm mapping file, or in the HQL, or how you model your objects, and all of a sudden you have a 10x increase in SQL statements requried..

I was thinking that instead of manually doing this, I could instead of have unit test that said that for Page A, 5 sql statements are okay, and for Page B 15 are okay. Then, when I make change, be able to run some unit tests and verify that these limits haven't been exceeded.

Since we have a relatively simple read/write webapp, without multi step pages etc, being able to count the number of SQL statements to load a page would be a fine measurement. Yes, it wouldn't take into account the effect of caching, which does help a lot, but even so, knowing Page 5 has crept from 5 to 6 statements is good information.

So, has anyone done anything like this? My thought is to write a Cactus testcase that would deploy the webapp into Tomcat, and then attach a listerner to something that recorded the sql statements. The testcase consists of generating the webpage. After the Cactus testcase finishes, assert the number of SQL statements issued was less then X.

I remember seeing an open source SQL tool that recorded every SQL statement, and then would play them back in reverse... I also thought about using the Interceptor function and using that as well. I could also do something like proxy the connection that Hibernate retrieves as well..

Any ideas? Suggestions?

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 11:00 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's pretty easy to implement a wrapper over java.sql.connection and add a counter in it.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.