Problems with EJB 2.1 - PowerPoint PPT Presentation

About This Presentation
Title:

Problems with EJB 2.1

Description:

... (Cabin cabin); public Cabin findCabin ... import com.titan.domain.Cabin; _at_Stateless ... { return manager.find(Cabin.class, pKey); TravelAgentBean: The Bean Class ... – PowerPoint PPT presentation

Number of Views:109
Avg rating:3.0/5.0
Slides: 28
Provided by: jerryc60
Category:
Tags: ejb | cabin | problems

less

Transcript and Presenter's Notes

Title: Problems with EJB 2.1


1
Problems with EJB 2.1
2
Deployment Descriptors
  • Complex
  • Multiple
  • Partly vendor dependent
  • Lack adequate defaults
  • Better graphical tools needed

3
Verbosity
  • Need two interfaces to specify one EJB.
  • Remote and local interface
  • Remote and local home interface
  • Must implement special EJB classes.
  • Numerous callback methods required.
  • Even normally-empty callbacks like ejbPostCreate
    must be specified

4
EJB Query Language
  • EJB QL is currently weak.
  • Strange object-oriented syntax
  • Does not implement full SQL language
  • Lacks functions and operations
  • Programmers are forced to resort to JDBC and SQL.
  • EJB 2.1 lacks vendor-independent
    object-relational mapping tools.

5
Testing
  • Entity beans are abstract classes.
  • Consequently, they are completely untestable
    outside the context of the container.

6
Whats Coming in EJB 3.0
EJB 3.0 Public Review Draft is on your CD (in
three parts). Proposed Final Review Draft due
to be approved in 2006.
7
Organization of the Specification Documents
  • EJB 3.0 Simplified API
  • EJB 3.0 Core Contracts and Requirements
  • Java Persistence API

8
EJB 3.0 Overview
  • Purpose is to reduce complexity of the EJB
    architecture from the enterprise application
    developers point of view.
  • Replace deployment descriptors with annotations
    in the source code (like javadoc comments).
  • Specify defaults representing the expected
    behaviors (configuration by exceptions).
  • Backward compatibility with EJB 2.1 (can mix and
    match).

continued
9
EJB 3.0 Overview
continued
  • Use of annotations to simplify JNDI lookup
    mechanisms and environmental dependencies.
  • Simplification of enterprise bean types.
  • Eliminate need for EJB component interfaces for
    session beans. Use plain old Java objects (POJOs)
    instead.
  • Eliminate need for home interfaces for session
    beans.

10
EJB 3.0 Overview
continued
  • Simplify entity bean persistence.
  • Object-relational persistence API will work with
    Hibernate, TopLink and JDO.
  • Eliminate all required interfaces for entities
    written to the new persistence API.
  • Enhancement of EJB QL.
  • Eliminate the requirement for the implementation
    of callback interfaces.
  • Improve ability for testing outside the container

11
Acknowledgement
  • The following slides are based on code that was
    kindly provided by Bill Burke, Chief Architect at
    JBoss.
  • It will appear in his new O'Reilly book
    "Enterprise JavaBeans (Fifth Edition)".

12
Developing an Entity Bean
package com.titan.domain import
javax.persistence. _at_Entity _at_Table(name"CABIN")
public class Cabin implements
java.io.Serializable private int id
private String name private int deckLevel
private int shipId private int bedCount
_at_Id _at_Column(name"CABIN_ID") public
int getId() return id public void
setId(int pk) id pk
_at_Column(name"CABIN_NAME") public String
getName() return name
Cabin The Bean Class
continued
13
Developing an Entity Bean
continued
_at_Column(name"CABIN_NAME") public String
getName() return name public void
setName(String str) name str
_at_Column(name"CABIN_DECK_LEVEL") public int
getDeckLevel() return deckLevel public void
setDeckLevel(int level) deckLevel level
_at_Column(name"CABIN_SHIP_ID") public int
getShipId() return shipId public void
setShipId(int sid) shipId sid
_at_Column(name"CABIN_BED_COUNT") public int
getBedCount() return bedCount public void
setBedCount(int bed) bedCount bed
14
Developing an Entity Bean
  • Annotations are objects, for example
  • _at_javax.persistence.Entity specifes a persistent
    entity managed by an EntityManager service.
  • _at_javax.persistence.Table specifies the database
    table to map to.
  • _at_javax.persistence.Column defines a field in the
    database table
  • _at_Id specifies the primary key of a row.
  • Setters and getters are no longer abstract
    methods as in EJB 2.1.

required
15
Developing an Entity Bean
  • Entity bean is a POJO.
  • Does not extend javax.ejb.EJBObject.
  • Bean class implements Serializable, therefore
  • Entity classes can be used as parameters and
    return values.
  • Can be used as data transfer objects between
    client and server.
  • Can be persisted in a database.

16
persistence.xml
ltpersistencegt ltpersistence-unitgt
ltnamegttitanlt/namegt ltjta-data-sourcegtjava/Defau
ltDSlt/jta-data-sourcegt lt/persistence-unitgt lt/pe
rsistencegt
17
Developing a Session Bean
package com.titan.travelagent import
javax.ejb.Remote import com.titan.domain.Cabin
_at_Remote public interface TravelAgentRemote
public void createCabin(Cabin cabin) public
Cabin findCabin(int id)
TravelAgentRemote The Remote Interface
18
Developing a Session Bean
package com.titan.travelagent import
javax.ejb.Stateless import javax.persistence.
import com.titan.domain.Cabin
_at_Stateless public class TravelAgentBean
implements TravelAgentRemote
_at_PersistenceContext(unitName"titan") private
EntityManager manager public void
createCabin(Cabin cabin)
manager.persist(cabin) public Cabin
findCabin(int pKey) return
manager.find(Cabin.class, pKey)
TravelAgentBean The Bean Class
19
Developing a Session Bean Annotations
  • _at_javax.ejb.Remote as opposed to Local.
  • _at_javax.ejb.Stateless as opposed to Stateful.
  • _at_javax.persistence.PersistenceContext gives
    access to the EntityManager.

20
CABIN Table in the Database
create table CABIN ( ID int primary key NOT
NULL, SHIP_ID int, BED_COUNT int,
NAME char(30), DECK_LEVEL int )
21
Creating a Client Application
package com.titan.clients import
com.titan.travelagent.TravelAgentRemote import
com.titan.domain.Cabin import
javax.naming. import java.util.Properties impor
t javax.rmi.PortableRemoteObject public class
Client_1 public static void main(String
args) try ontext jndiContext
new InitialContext() // use the jndi
properties file Object ref
jndiContext.lookup (TravelAgentRemote.class.ge
tName()) TravelAgentRemote dao (
TravelAgentRemote)PortableRemoteObject.na
rrow (ref,TravelAgentRemote.class)
continued
22
Creating a Client Application
continued
Cabin cabin_1 new Cabin()
cabin_1.setId(1) cabin_1.setName("Mast
er Suite") cabin_1.setDeckLevel(1)
cabin_1.setShipId(1)
cabin_1.setBedCount(3)
dao.createCabin(cabin_1) Cabin
cabin_2 dao.findCabin(1)
System.out.println(cabin_2.getName())
System.out.println(cabin_2.getDeckLevel())
System.out.println(cabin_2.getShipId())
System.out.println(cabin_2.getBedCount())
catch (javax.naming.NamingException
ne) ne.printStackTrace()
23
INSTALL.html
24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
Coming May 1, 2006
Enterprise JavaBeans 3.0 by Bill Burke and
Richard Monson-Haefel, OReilly, ISBN 059600978X
Write a Comment
User Comments (0)
About PowerShow.com