Java Reference
In-Depth Information
CHAPTER 8
n n n
Using the Session
Y
ou may have noticed that the
Session
object is the central point of access to Hibernate
functionality. We will now look at what it embodies and what that implies about how you
should use it.
Sessions
From the examples in the earlier chapters, you will have noticed that a small number of
classes dominate our interactions with Hibernate. Of these,
Session
is the linchpin.
The
Session
object is used to create new database entities, read in objects from the
database, update objects in the database, and delete objects from the database. It allows
you to manage the transaction boundaries of database access, and (in a pinch) it allows
you to obtain a traditional JDBC connection object so that you can do things to the data-
base that the Hibernate developers have not already considered in their existing design
(precious little).
If you are familiar with the JDBC approach, it helps to think of a
Session
object as being
somewhat like a JDBC connection, and the
SessionFactory
, which provides
Session
objects,
as being somewhat like a
ConnectionPool
, which provides
Connection
objects. These similari-
ties in roles are illustrated in Figure 8-1.
Figure 8-1.
Similarities between Hibernate and JDBC objects
179
Search WWH ::
Custom Search