Java Reference
In-Depth Information
Table 4.2 shows the key methods defined by the
Session
and
PersistenceMan-
ager
interfaces.
Table 4.2
Examples of JDO
PersistenceManager
and Hibernate
Session
methods
Hibernate
Session
JDO PersistenceManager
Making an object persistent
save()
makePersistent()
Loading an object
load()
getObjectById()
Deleting an object
delete()
deletePersistent()
Creating a query
createQuery()
createNamedQuery()
newQuery()
newNamedQuery()
Accessing the transaction
object
beginTransaction()
currentTransaction()
Closing the connection
close()
close()
As you can see,
Session
and
PersistenceManager
define methods with very similar
purposes. For example, the
save()
and
makePersistent()
methods persist an
object, and the
load()
and
getObjectById()
methods load the specified instance.
There are also methods for creating queries, accessing the transaction object, and
closing the connection.
4.3.3
Query language
Hibernate and
JDO
provide several options for executing queries. An application
can use either
object queries
, which are queries expressed in terms of objects, or
SQL native queries
, which are written in
SQL
.
JDO
and Hibernate provide a textual
query language for writing object queries. In addition, Hibernate has what are
called
criteria queries
, which are nontextual queries.
Object queries
Object queries are the easiest to use because they take full advantage of the
ORM
framework.
JDO
and Hibernate each have a textual query language for object que-
ries.
JDO
object queries are written in
JDO
Query Language (
JDOQL
), whose syn-
tax is based on Java expressions; Hibernate provides Hibernate Query Language
(
HQL
), whose syntax is similar to
SQL
.
JDOQL
and
HQL
queries usually return per-
sistent objects, but you can also write
projection queries
, which return
DTO
s and
other values.
Search WWH ::
Custom Search