Entity Bean - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Entity Bean

Description:

have primary keys: unique object identifier ... has the same number and types of arguments as its matching ejbCreate method in ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 28
Provided by: dct2
Category:
Tags: bean | entity | keys

less

Transcript and Presenter's Notes

Title: Entity Bean


1
Entity Bean
  • Chuyên d? L?p trình Java J2EEChuong 15
  • Biên so?n Th.S Nguy?n van Lành

2
Concepts
  • An entity bean represents persistent data stored
    in one row of a database table .
  • When an entity bean is created, the data is
    written to the appropriate database table row,
    and if the data in an entity bean is updated, the
    data in the appropriate database table row is
    also updated
  • Entity beans differ from session beans in several
    ways.
  • Entity beans are persistent entity bean's state
    exists beyond the lifetime of the application
  • allow shared access may be shared by multiple
    clients
  • have primary keys unique object identifier
  • may participate in relationships with other
    entity beans

3
When to Use Entity Beans
  • The bean represents a business entity, not a
    procedure.
  • For example, CreditCardEJB would be an entity
    bean
  • CreditCardVerifierEJB would be a session bean.
  • The bean's state must be persistent

4
Types of persistent management
  • Bean-Managed Persistence
  • the bean developer takes responsibility for
    persistent storage in attributes
  • Container-Managed Persistence 1.1
  • persistent attributes are defined as attributes
    of the bean class and given in the deployment
    descriptor
  • Container-Managed Persistence 2.0/2.1
  • The bean developer works with an abstract bean
    class
  • defines abstract access methods for reading and
    writing of attributes (During deployment the EJB
    container generates a derived class that
    implements all the abstract methods )

5
Constitution of a entity bean
  • Remote interface
  • defines the business methods of the bean.
  • Home interface
  • defines the methods that allow a client to create
    and find an entity bean
  • Enterprise Bean class
  • provides the implementation for the business
    methods, finder methods, home methods
  • Primary key class
  • makes it possible to identify all entity bean
    identities uniquely
  • Deployment Descriptor
  • This configuration document defines the bean's
    runtime attributes, such as its transaction or
    security attributes
  • Helper classes

6
Remote Interface
  • Each method in the remote interface must match a
    method in the enterprise bean class.
  • The signatures of the methods in the remote
    interface must be identical to the signatures of
    the corresponding methods in the enterprise bean
    class.
  • The arguments and return values must be valid RMI
    types.
  • The throws clause must include java.rmi.RemoteExce
    ption

7
Home Interface
  • defines the methods that allow a client to create
    and find an entity bean
  • create Method
  • has the same number and types of arguments as its
    matching ejbCreate method in the enterprise bean
    class.
  • returns the remote interface type of the
    enterprise bean.
  • The throws clause includes the exceptions
    specified by the throws clause of the
    corresponding ejbCreate and ejbPostCreate
    methods.
  • The throws clause includes the javax.ejb.CreateExc
    eption java.rmi.RemoteException

8
Entity bean creation
9
Home Interface
  • finder Method
  • Every finder method in the home interface
    corresponds to a finder method in the entity bean
    class.
  • The name of a finder method in the home interface
    begins with find, whereas the corresponding name
    in the entity bean class begins with ejbFind
  • The number and types of arguments must match
    those of the corresponding method in the entity
    bean class.
  • The return type is the entity bean's remote
    interface type, or a collection of those types.
  • The exceptions in the throws clause include those
    of the corresponding method in the entity bean
    class.
  • The throws clause contains the javax.ejb.FinderExc
    eption java.rmi.RemoteException

10
Home Interface
  • finder Method in bean class
  • All finder methods must begin with ejbFind.
  • You must have at least one finder method, called
    ejbFindByPrimaryKey.
  • You can have many different finder methods, each
    with different names and different parameters.
  • A finder method must return either the primary
    key for the entity bean it finds or a collection
    of primary keys if it finds more than one.

11
Home Interface
  • home Method
  • Each home method definition in the home interface
    corresponds to a method in the entity bean class.
  • In the home interface, the method name is
    arbitrary, provided that it does not begin with
    create or find.
  • In the bean class, the matching method name
    begins with ejbHome.
  • For example, in the SavingsAccountBean class the
    name is ejbHomeChargeForLowBalance, but in the
    SavingsAccountHome interface the name is
    chargeForLowBalance
  • The throws clause contains the java.rmi.RemoteExce
    ption

12
BMP guidelines
13
BMP guidelines
14
BMP guidelines
15
BMP guidelines
16
(No Transcript)
17
Bean-DBMS synchronization
18
CMP Entity Beans
  • CMP Entity Beans Are Subclassed
  • database-independent
  • The container generates the JDBC code by
    subclassing your entity bean class.
  • CMP Entity Beans Have No Declared Fields
  • CMP Entity Beans Have a Query Language
  • CMP Entity Beans Can Have ejbSelect() Methods

19
Bean instance Pooling
20
CMP Guidelines
21
CMP Guidelines
22
CMP Guidelines
23
(No Transcript)
24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com