Hi,
this post is about the same problem:
http://forum.hibernate.org/viewtopic.php?t=986012
So it is not possible ( in an efficient way);
We had the same problem and solved it in a quite satisfying way adding some extra fields to the Lucene index, so that you can use standard HQL when no free-text has been selected, or use a Lucene query for all fields when a mixed input has been selected.
An example input form to search a user: a combobox "nationality", a free-text "name":
A)when only "nationality" is filled in, we search by HQL using nation-id
B)when the "name" is filled in, we search by Lucene
C)when both are filled in, we also search by Lucene, having the nationality-id encoded as a field in the Lucene documents.
The intersection solution could work fine if you may force your user to only see the first page, and then have to scroll by using a "next" button;
Unfortunately you usually want to show a "total count" and provide a "page20" button...
If you really want to go on with the "intersection solution" I would suggest you to fetch from DB only the primary keys, using a scrollable result and adding them all to a set;
Some DBMS integrate a full-text "plugin" so you can mix the full-text query with SQL, but performance is horrible as they suffer from the same problem.
Quote:
I am wondering if the way hibernate does its paging is described somewhere so that we can have a look to understand how it works
It depends on the DB.. easiest way is to enable SQL logging so you can see what it does.