tags:

views:

22

answers:

1

NHibernate (for .Net) has an interface called IMultiQuery which you can instantiate an implementation for using ISession.CreateMultiQuery(). A multi-query allows one to run multiple hql statements in a single batch. I can't seem to find an equivalent feature in Hibernate (for Java).

Multi-query would be perfect for the java application I'm working on right now. It has about 10 HQL select queries running inside a tight loop. Load testing shows that it's about 50% too slow (or said in another way, it takes twice as long as required). My analysis says that almost all of the time is spent on network latency between the app server and the database. I can definitely rewrite the code to avoid the tight loop, but that was the simplest design and it's already been QAed for correctness.

So, if I can somehow shoot off all 10 HQL queries in a single batch, that should give more than enough of a performance boost without resorting to more drastic and bug-prone measures. Is there any way to do that with Hibernate in Java?

A: 

I'm not aware of a Java equivalent of the Multi Query and I think this feature is specific to the .net version (because it is database specific). From the NHibernate documentation:

17.7. Multi Query

Multi query is executed by concatenating the queries and sending the query to the database as a single string. This means that the database should support returning several result sets in a single query. At the moment this functionality is only enabled for Microsoft SQL Server and SQLite.

Pascal Thivent
Thanks for pointing that out. Can you think of any alternatives?
jthg