Java Reference
In-Depth Information
A standardized
O/R
mapping mechanism
■
Support for inheritance
■
Embedded objects whose fields are mapped to the same table as the entity
bean's fields
■
Optimistic locking with version numbers
■
EJB 3
also enhances the
EJB
query language with new features such as Hibernate-
style fetch joins for eagerly loading objects and bulk update and delete. In addi-
tion, queries can be defined either statically or generated dynamically.
Improved persistence API
As I mentioned earlier,
EJB 3
has a new and improved persistence
API
that is quite
similar to the
API
s provided by
JDO
and Hibernate. As figure 10.1 shows, the
API
consists of interfaces that play the role of connection factory, connection, transac-
tion, and query. There is also a
Persistence
class that provides methods for creat-
ing the
EJB 3
equivalent of the connection factory.
The
EntityManager
replaces the entity bean home interfaces and is equivalent
to the
JDO
PersistenceManager
and Hibernate
Session
. It defines methods for
creating, deleting, and querying entity beans. For example, the
create()
method
Persistence
createEntityManagerFactory() {static}
...
<<creates>>
EntityManager
Factory
createEntityManager()
close()
...
<<creates>>
<<interface>>
EntityManager
Entity
Transaction
<<interface>>
Query
create()
remove()
find()
Query createQuery()
Query createNamedQuery()
EntityTransaction
getTransaction()
...
<<creates>>
<<creates>>
begin()
commit()
rollback()
...
setParameter()
List getResultList()
executeUpdate()
...
Figure 10.1
The EJB 3 persistence API
Search WWH ::
Custom Search