Update of /cvsroot/hibernate/Hibernate2/doc/reference/src
In directory sc8-pr-cvs1:/tmp/cvs-serv6667/src
Modified Files:
advanced_or_mapping.xml query_language.xml
Log Message:
Integrated more FAQs
Index: advanced_or_mapping.xml
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/doc/reference/src/advanced_or_mapping.xml,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** advanced_or_mapping.xml 26 Apr 2003 01:42:29 -0000 1.18
--- advanced_or_mapping.xml 26 Apr 2003 19:36:25 -0000 1.19
***************
*** 491,494 ****
--- 491,501 ----
</itemizedlist>
+ <para>
+ You can use the <literal>filter()</literal> method of the Hibernate Session API to
+ get the size of a collection without initializing it:
+ </para>
+
+ <programlisting><![CDATA[( (Integer) s.createFilter( collection, "select count(*)" ).iterate().next() ).intValue()]]></programlisting>
+
</sect2>
Index: query_language.xml
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/doc/reference/src/query_language.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** query_language.xml 21 Apr 2003 06:23:42 -0000 1.11
--- query_language.xml 26 Apr 2003 19:36:25 -0000 1.12
***************
*** 670,674 ****
</sect1>
!
<sect1 id="query-language-s10">
<title>Examples</title>
--- 670,674 ----
</sect1>
!
<sect1 id="query-language-s10">
<title>Examples</title>
***************
*** 792,797 ****
order by account.type.sortOrder, account.accountNumber, payment.dueDate]]></programlisting>
! </sect1>
!
</chapter>
--- 792,866 ----
order by account.type.sortOrder, account.accountNumber, payment.dueDate]]></programlisting>
! </sect1>
!
! <sect1 id="query-language-s11">
! <title>Tips & Tricks</title>
!
! <para>
! You can count the number of query results without actually returning them:
! </para>
!
! <programlisting><![CDATA[( (Integer) session.iterate("select count(*) from ....").next() ).intValue()]]></programlisting>
!
! <para>
! To order a result by the size of a collection, use the following query
! for a one-to-many or many-to-many association:
! </para>
!
! <programlisting><![CDATA[select user
! from user in class eg.User,
! msg in user.messages.elements
! group by user
! order by count(msg)]]></programlisting>
!
! <para>
! If your database supports subselects, you can place a condition upon selection
! size in the where clause of your query:
! </para>
!
! <programlisting><![CDATA[from user in class eg.User
! where user.messages.size >= 1]]></programlisting>
!
! <para>
! If your database doesn't support subselects or you're dealing with a one-to-many
! or a many-to-many association, use the following query:
! </para>
!
! <programlisting><![CDATA[select user
! from user in class eg.User,
! msg in user.messages.elements
! group by user
! having count(msg) >= 1]]></programlisting>
!
! <para>
! As this solution can't return a <literal>User</literal> with zero messages
! because of the implicit inner join, se following form is also useful:
! </para>
!
! <programlisting><![CDATA[select user
! from eg.User as user
! left join user.messages.elements as msg
! group by user
! having count(msg) = 0]]></programlisting>
!
! <para>
! Properties of a JavaBean can be bound to named query parameters:
! </para>
!
! <programlisting><![CDATA[Query q = s.createQuery("from foo in class Foo where foo.name=:name and foo.size=:size");
! q.setProperties(fooBean); // fooBean has getName() and getSize()
! List foos = q.list();]]></programlisting>
!
! <para>
! Collections are pageable when using the query API:
! </para>
!
! <programlisting><![CDATA[Query q = s.createFilter( collection, "" ); // the trivial filter
! q.setMaxResults(PAGE_SIZE);
! q.setFirstResult(PAGE_SIZE * pageNumber);
! List page = q.list();]]></programlisting>
!
! </sect1>
!
</chapter>
|