study notes for EJB 3 in action (II)

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. 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值