O'Reilly logo

Working with NHibernate 3.0 by Benjamin Perkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2

Using HQL

In the previous chapter, you learned about a few of NHibernate's capabilities, such as lazy loading, Interceptors, logging, and Events. Most important, you learned how to install and configure NHibernate so that it can be used to retrieve data from a database. This chapter addresses using Hibernate Query Language (HQL), which is a fully object-oriented query language similar in appearance to SQL. This chapter covers the following topics:

  • CreateQuery, CreateMultiQuery, GetNamedQuery, DetachedQuery, DetachedNamedQuery, and Futures
  • Implementing paging
  • Creating a round-trip database counter

INTRODUCTION

The IQuery API is used for executing HQL queries on a database. HQL is my personal preference when I don't have or need a specific class to store the results of a query. As shown later in this chapter, some NHibernate methods require using a strongly typed class to retrieve data from the database.

Many HQL methods are made available via the Session interface to execute a query against the database. Figure 2-1 shows a graphical representation of the methods, such as CreateQuery and CreateNamedQuery, and their corresponding execution methods, such as List<T>() or List(), for using the IQuery API. This chapter describes each of the methods and provides examples demonstrating how they can be used to fulfill most of the GuitarStore project requirements defined in Chapter 1.

FIGURE 2-1

Figure 2-2 shows the IQuery, AbstractQueryImpl, and QueryImpl class diagram. IQuery is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required