您的位置:首页 > 其它

study notes for EJB 3 in action (II)

2007-06-17 22:45 417 查看
EJB 3 in Action

1.2 Understanding EJB types

As we've briefly metioned, session beans and message-driven beans (MDBs) are used to build business logic, and they live in the container, which manages these beans and provides services to them. Entities are used to model the persistence part of an application. Like the container, it is the persistence provider that manages entities.

1.2.1 Session beans
A session bean is invoked by a client for the purpose of performing a specific business operation, such as checking the credit history for a customer. The name session implies that a bean instance is available for the duration of a "unit of work" and does not survive a server crash or shutdown. There are two types of session beans: stateful and stateless.

A stateful session bean automatically saves bean state between client invocation without your having to write any additional code. In contrast, stateless session beans do not maintain any state and model application services that can be completed in a single client invocation.

A session bean can be invoked either locally or remotely using Java RMI. A stateless session bean can be exposed as a web service.

1.2.2 Message-driven beans
Clients never invoke MDB methods directly. Instead, MDBs are triggered by messages sent to a messaging server, which enables sending asynchronous messages between system components.

1.2.3 Entities and the Java Persistence API (JPA)
Since JPA standardizes ORM frameworks for the Java platform, you can plug in ORM products like JBoss Hibernate, Oracle TopLink, or BEA Kodo as the underlying JPA "persistence provider" for your application.

Entities
Entities are the Java objects that are persisted into the database.  Here's another perfectly valid way of looking at entities: they are the OO representations of the application data stored in the database. In this sense, entities survive container crashes and shutdown.

The EntityManager
The JPA EntityManager interface manages entities in terms of actually providing persistence services. While entities tell a JPA provider how they map to the database, they do not persist themselves. The EntityManager interface reads the ORM metadata for an entity and performs persistence operations.

The Java Persistence Query Language
JPA provides a specialized SQL-like query language called the Java Persistence Query Language (JPQL) to search for entities saved into the database. In addition, JPA supports native, database-specific SQL, in the rare cases where it is worth using. 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息