Hi All,
I'm quite new to this hibernate stuff, so please excuse my ignorance if I'm being really daft. I'm exploring the hibernate statistics object so that I can measure the performance of the queries in my application (generate_statistics is true).
Although I can see in the log (show_sql is true) that queries are being being sent to the database, the count in the statistics does not reflect them. I've isolated it down to the following case where two queries are sent to the database, but only one is shown in the statistics.
Hibernate version:
Hibernate 3.1.2
Mapping documents:
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://pvr/test</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">Test</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.autocommit">false</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="show_sql">true</property>
<property name="generate_statistics">true</property>
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="c3p0.max_size">100</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">10</property>
<property name="c3p0.timeout">100</property> <!-- seconds -->
<mapping resource="tv/clever/hibernate/mapping/Customer.hbm.xml" />
<mapping resource="tv/clever/hibernate/mapping/Book.hbm.xml" />
</session-factory>
Code between sessionFactory.openSession() and session.close():
logStats("1");
List customers = session.createQuery("select c from Customer as c").list();
logStats("2");
Customer customer = (Customer)customers.get(0);
log.info("customer: " + customer);
logStats("3");
log.info("customer books: " + customer.getBooks());
logStats("4");
protected void logStats(String x) {
Statistics s = HibernateSessionFactory.currentSession().getSessionFactory().getStatistics();
log.info("(" + x + ") queryCount: " + s.getQueries().length + ", queriesExecutedToDatabase" + s.getQueryExecutionCount());
}
Full stack trace of any exception that occurs:
No Exception
Name and version of the database you are using:
mysql 4.1.16-nt
Debug level Hibernate log excerpt:
5378 [main] INFO tv.clever.test.HibernateTest - (1) queryCount: 0, queriesExecutedToDatabase0
Hibernate: select customer0_.id as id0_, customer0_.firstname as firstname0_, customer0_.lastname as lastname0_, customer0_.age as age0_ from customer customer0_
5889 [main] INFO tv.clever.test.HibernateTest - (2) queryCount: 1, queriesExecutedToDatabase1
5889 [main] INFO tv.clever.test.HibernateTest - customer: Customer [id=17, firstname=Carsten, lastname=Liebzeit]
5889 [main] INFO tv.clever.test.HibernateTest - (3) queryCount: 1, queriesExecutedToDatabase1
Hibernate: select books0_.customer_fk as customer2_1_, books0_.id as id1_, books0_.id as id1_0_, books0_.customer_fk as customer2_1_0_, books0_.title as title1_0_, books0_.author as author1_0_, books0_.borrowallowed as borrowal5_1_0_ from book books0_ where books0_.customer_fk=?
5929 [main] INFO tv.clever.test.HibernateTest - customer books: [Book [id=18, title=Hibernation in winter]]
5929 [main] INFO tv.clever.test.HibernateTest - (4) queryCount: 1, queriesExecutedToDatabase1
5929 [main] INFO tv.clever.test.HibernateTest - (end) queryCount: 1, queriesExecutedToDatabase1
Any help would be appreciated,
Regards,
George
|