MultiQuery / Named Query

37 views
Skip to first unread message

Jamie Fraser

unread,
Sep 25, 2008, 4:04:05 AM9/25/08
to nhu...@googlegroups.com
I'm trying to execute a stored procedure (I've also tried modifying
this into a SQL statement and called it via a named query) which
returns 2 result sets.

First result set is the data (search results, essentially).
Second result set is the count of results.

I'm not sure if a Multiquery is the right thing to use - from what I
understand a MQ will allow me to execute N queries in a batch and
present single results for each one, whereas I want to execute a
single query and get 2 results from it.

Can anyone advise what to do?

Ayende Rahien

unread,
Sep 25, 2008, 4:05:31 AM9/25/08
to nhu...@googlegroups.com
NHibernate will not understand 2 results sets. You will have to deal with that manually.
You can turn that into two different queries and call them using multi query, however.

Jamie Fraser

unread,
Sep 25, 2008, 8:30:35 AM9/25/08
to nhu...@googlegroups.com
Okay, when I have 2 named queries (declared like:

var fullTextSearchQuery = session.GetNamedQuery("FullTextSearch")
.SetResultTransformer(Transformers.AliasToBean(typeof(SearchResultItem)))
.SetString("SearchString", searchString)
.SetInt32("PageSize", searchParams.NumberResults)
.SetInt32("PageNumber", searchParams.PageNumber);

var fullTextCountQuery = session.GetNamedQuery("FullTextCount")
.SetString("SearchString", searchString)
.SetInt32("PageSize", searchParams.NumberResults)
.SetInt32("PageNumber", searchParams.PageNumber);

They both work fine.

However if I do

var results = session.CreateMultiQuery()
.AddNamedQuery("FullTextSearch")
.AddNamedQuery("FullTextCount")
.SetString("SearchString", searchString)
.SetInt32("PageSize", searchParams.NumberResults)
.SetInt32("PageNumber", searchParams.PageNumber)
.List();

I get an error saying "query must begin with SELECT or FROM"

What am I doing wrong?

Ayende Rahien

unread,
Sep 25, 2008, 8:32:58 AM9/25/08
to nhu...@googlegroups.com
This looks like a bug, please create a stand alone test case for this.

Jamie Fraser

unread,
Sep 25, 2008, 9:01:52 AM9/25/08
to nhu...@googlegroups.com
Damn, not having much luck.. Castle bug yesterday and this today!

Test case attached - just remember and point it to any local DB via
hibernate.cfg.xml (the named queries are very simple, they don't
actually hit any tables so it won't matter which DB NH points to).

-Jamie

MultiQueryNamedQueryTests.zip

Jamie Fraser

unread,
Sep 25, 2008, 5:29:21 PM9/25/08
to nhu...@googlegroups.com
Did the test case attachment come through alright? Anyone know if this
is actually a bug or a misinterpretation of how to use MultiQuery with
Named Queries?

Ayende Rahien

unread,
Sep 27, 2008, 12:22:03 AM9/27/08
to nhu...@googlegroups.com
Okay, I found out what was going on. The issue is with multi query implementation. It assumes that the query that you pass it is always an HQL query.
From a short review of the code, it looks like it would be possible to change that, but I don't currently have the time to dedicate to this.

Jamie Fraser

unread,
Sep 27, 2008, 7:11:48 AM9/27/08
to nhu...@googlegroups.com
Okay - thanks for finding this out for me. Are there other batching
options open to me? Essentially I just want to execute 2 named queries
with the minimum of overhead....

Ayende Rahien

unread,
Sep 27, 2008, 7:14:10 AM9/27/08
to nhu...@googlegroups.com
Session.Connection.CreateCommand()

Fabio Maulo

unread,
Sep 27, 2008, 8:23:23 AM9/27/08
to nhu...@googlegroups.com
a JIRA for this issue ?
thanks.

2008/9/27 Ayende Rahien <aye...@ayende.com>



--
Fabio Maulo

Jamie Fraser

unread,
Sep 30, 2008, 8:45:06 AM9/30/08
to nhu...@googlegroups.com
http://jira.nhibernate.org/browse/NH-1508

(I don't think anyone else added it so I did).

Reply all
Reply to author
Forward
0 new messages