How To Write A Bean In Java (Java) 2.5.1.2 (Java 2.4.2) (Java.Net) (Javax) 2 (Java Bean) ( Java Bean) 2-4.5



Similar documents
Java E-Commerce Martin Cooke,

EJB & J2EE. Component Technology with thanks to Jim Dowling. Components. Problems with Previous Paradigms. What EJB Accomplishes

Component Middleware. Sophie Chabridon. INT - INF Department - Distributed Systems team 2006

Software Development using MacroMedia s JRun

Enterprise JavaBeans Fundamentals

Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

Chapter 4. Architecture. Table of Contents. J2EE Technology Application Servers. Application Models

Introduction to Entity Beans

Java OGSI Hosting Environment Design A Portable Grid Service Container Framework

Using the Beans Development Kit 1.0. September A Tutorial. Alden DeSoto. Sept Garcia Avenue Mountain View, CA U.S.A.

Aufgabenstellung. Aufgabenstellung

What Is the Java TM 2 Platform, Enterprise Edition?

INTRODUCTION TO JAVA BEANS

Java-technology based projects

WebOTX Application Server

New Methods for Performance Monitoring of J2EE Application Servers

Enterprise JavaBeans 3.1

Glassfish, JAVA EE, Servlets, JSP, EJB

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS

Das Spring Framework - Einführung in leichtgewichtige J2EE Architektur. Jürgen Höller. Organized by:

Java 2 Platform, Enterprise Edition (J2EE): Enabling Technologies for EAI

Elements of Advanced Java Programming

Automatic generation of distributed dynamic applications in a thin client environment

White paper. IBM WebSphere Application Server architecture

PERFORMANCE MONITORING OF JAVA COMPONENT-ORIENTED DISTRIBUTED APPLICATIONS

Distributed Objects and Components

3-Tier Architecture. 3-Tier Architecture. Prepared By. Channu Kambalyal. Page 1 of 19

The Evolution to Components. Components and the J2EE Platform. What is a Component? Properties of a Server-side Component

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

IBM Rational Rapid Developer Components & Web Services

J2EE Web Development. Agenda. Application servers. What is J2EE? Main component types Application Scenarios J2EE APIs and Services.

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

10. Ausblick Zusammenfassung. Datenbanksysteme und ihre Realisierung. Datenmodelle. Anwendungen. RDM (Kap. 3) Transaktionen (Kap.

Module 13 Implementing Java EE Web Services with JAX-WS

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

What is Middleware? Software that functions as a conversion or translation layer. It is also a consolidator and integrator.

A Flexible Security Architecture for the EJB Framework

CGI Vs. Java - Which is Better For Marketing

Architectural Overview

Net-WMS FP Net-WMS SPECIFIC TARGETED RESEARCH OR INNOVATION PROJECT. Networked Businesses. D.8.1 Networked architecture J2EE compliant

Announcements. Comments on project proposals will go out by in next couple of days...

Enterprise Application Integration

Objectives. Software Development using MacroMedia s JRun. Enterprise Application Model. Topics for Discussion

WEB SERVICES. Revised 9/29/2015

Introduction to Sun ONE Application Server 7

Developing Java Web Services

JSLEE and SIP-Servlets Interoperability with Mobicents Communication Platform

How To Create A C++ Web Service

Chapter 5 Application Server Middleware

25 May Code 3C3 Peeling the Layers of the 'Performance Onion John Murphy, Andrew Lee and Liam Murphy

A standards-based approach to application integration

JAVA API FOR XML WEB SERVICES INTRODUCTION TO JAX-WS, THE JAVA API FOR XML BASED WEB SERVICES (SOAP, WSDL)

Service Oriented Architectures

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Writing Grid Service Using GT3 Core. Dec, Abstract

Java EE 7: Back-End Server Application Development

Outline SOA. Properties of SOA. Service 2/19/2016. Definitions. Comparison of component technologies. Definitions Component technologies

Client/server is a network architecture that divides functions into client and server

Virtual Credit Card Processing System

How To Protect Your Computer From Being Hacked On A J2Ee Application (J2Ee) On A Pc Or Macbook Or Macintosh (Jvee) On An Ipo (J 2Ee) (Jpe) On Pc Or

Productivity Comparison for Building Applications and Web Services

Reusing Existing * Java EE Applications from Oracle SOA Suite

Sun Certified Enterprise Architect for J2EE Technology Study Guide

Core J2EE Patterns, Frameworks and Micro Architectures

How To Develop An Application Developer For An Ubio Websphere Studio 5.1.1

JAVA ENTERPRISE IN A NUTSHELL. Jim Farley and William Crawford. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo.

Infrastructure for Automatic Dynamic Deployment of J2EE Applications in Distributed Environments

An Infrastructure for the Dynamic Distribution of Web Applications and Services 1

Applets, RMI, JDBC Exam Review

Oracle Application Server 10g

Performance Comparison of Java Application Servers

Motivation Definitions EAI Architectures Elements Integration Technologies. Part I. EAI: Foundations, Concepts, and Architectures

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

Listeners. Formats. Free Form. Formatted

Java Technology in the Design and Implementation of Web Applications

Building and Using Web Services With JDeveloper 11g

ActiveVOS Server Architecture. March 2009

PROGRESS Portal Access Whitepaper

Fundamentals of Java Programming

COM 440 Distributed Systems Project List Summary

DEPLOYMENT ARCHITECTURE FOR JAVA ENVIRONMENTS

Lösungsvorschläge zum Übungsblatt 13: Fortgeschrittene Aspekte objektorientierter Programmierung (WS 2005/06)

JBS-102: Jboss Application Server Administration. Course Length: 4 days

Introduction to WebSphere Process Server and WebSphere Enterprise Service Bus

Learn Oracle WebLogic Server 12c Administration For Middleware Administrators

MDA Overview OMG. Enterprise Architect UML 2 Case Tool by Sparx Systems by Sparx Systems

Rice University 6100 Main Street, MS-132 Houston, TX, 77005, USA

SAP Web Application Server 6.30: Learning Map for Development Consultants

How To Develop A Web Service In A Microsoft J2Ee (Java) 2.5 (Oracle) 2-Year Old (Orcient) 2Dj (Oracles) 2E (Orca) 2Gj (J

SCA-based Enterprise Service Bus WebSphere ESB

Limitations of Object-Based Middleware. Components in CORBA. The CORBA Component Model. CORBA Component

Copyright. Restricted Rights Legend. Trademarks or Service Marks. Copyright 2003 BEA Systems, Inc. All Rights Reserved.

A Framework for Prototyping J2EE Replication Algorithms

Redbooks Paper. WebSphere Application Server V5 Architecture. Carla Sadtler

Building Web Applications, Servlets, JSP and JDBC

Transcription:

JavaBeans Distributed Object Systems 9 Javabeans/EJB Piet van Oostrum Oct 9, 2008 Java Component technology: Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools Standard API to communicate with the Bean Bean must be configurable Bean must reveal information about itself will be used by IDE Graphical and non-graphical Comparable to ActiveX components Piet van Oostrum 1 JavaBeans model Javabeans often use events to communicate with each other Events are sent when Bean state changes Others can register to be notified Persistence can be used to store Bean state Parts of a Bean Runtime Interface Configuration Design Time Interface Instantiation and Activation Serialization/Persistence Reflection Most are optional! Piet van Oostrum 2 Piet van Oostrum 3 Example: Thermostat Bean Design Issues Usually the following are highly preferred: Default Constructor Implementation of Serializable Set/Get methods for properties Add/remove methods for event listeners JDK 1.1 Event model Thread safe Security (Applets) Piet van Oostrum 4 Piet van Oostrum 5 slides9.pdf October 9, 2008 1

Example Custom Property Editor Piet van Oostrum 6 Piet van Oostrum 7 Event Model Same model as AWT in JDK 1.1 and beyond AWT/Swing components are basic Beans EventObjects and EventListeners Examples of Events: GUI events (mouse/keyboard) Database Changes Response to requests (asynchronous) Property Changes in Bean Bean Properties A property xxx should have methods getxxx and setxxx IDE can find out which properties are available by introspection Property editor can often do conversion automatically Some types cannot be handled nicely (e.g. enumerations) Indexed properties (arrays) use specialized set/get methods, e.g. public void setcolortable(int index, Color value); public Color getcolortable(int index); public void setcolortable(color values[]); public Color[] getcolortable(); Piet van Oostrum 8 Piet van Oostrum 9 Bound Properties A bound property supports notification of changes In the bean: private PropertyChangeSupport changes = new PropertyChangeSupport(this); public void addpropertychangelistener( PropertyChangeListener p) changes.addpropertychangelistener(p); public void removepropertychangelistener( PropertyChangeListener p) changes.removepropertychangelistener(p); Bound Properties Set method must fire a notification public void setlevel(int level) int oldlv = this.level; this.level = level; changes.firepropertychange("level", new Integer(oldlv), new Integer(level)); Clients can add and remove PropertyChangeListeners Piet van Oostrum 10 Piet van Oostrum 11 slides9.pdf October 9, 2008 2

Constrained properties Additional Functionality above Bound properties: notified listener can veto the property change private VetoableChangeSupport vetoes = new VetoableChangeSupport(this); public void addvetoablechangelistener( VetoableChangeListener v) vetoes.addvetoablechangelistener(v); Usage of Constrained Properties public void setlevel(int level) throws PropertyVetoException vetoes.firevetoablechange("level", new Integer(this.level), new Integer(level)); int oldlv = this.level; this.level = level; changes.firepropertychange("level", new Integer(oldlv), new Integer(level)); public void removevetoablechangelistener( VetoableChangeListener v) vetoes.removevetoablechangelistener(v); Piet van Oostrum 12 Piet van Oostrum 13 Usage of Constrained Properties In the listener: public void vetoablechange (PropertyChangeEvent e) throws PropertyVetoException //... raise the PropertyVetoException // if it doesn t agree with the change Introspection Java provides reflection: You can find out information about classes. This is used by IDE s to get (a.o.) the names of properties Introspector class gives higher-level support for info about a Bean (properties, events, and methods). It uses implicit info from the MyBean class/superclasses, and explicit info from a separate MyBeanBeanInfo class. This information is used to build a BeanInfo object The exception is caught by the JavaBeans framework, not by the set method. Piet van Oostrum 14 Piet van Oostrum 15 Example BeanInfo For a Bean called Hire with a bound property salary : import java.beans.*; public class HireBeanInfo extends SimpleBeanInfo public PropertyDescriptor[] getpropertydescriptors() try PropertyDescriptor pd1 = new PropertyDescriptor("salary", Hire.class); pd1.setbound(true); return new PropertyDescriptor[] pd1; catch (Exception e) return null; Property Editors In the Beans Development Kit: Default properties (Progress Bar) Piet van Oostrum 16 Piet van Oostrum 17 slides9.pdf October 9, 2008 3

Property Editors Customized Property Editors Restricted by BeanInfo: department can be choosen from a list of values (enumeration) : it needs a customized property editor Piet van Oostrum 18 Piet van Oostrum 19 Customized Property Editors public class HireBeanInfo extends SimpleBeanInfo public PropertyDescriptor[] getpropertydescriptors() try PropertyDescriptor pd1 = new PropertyDescriptor("salary", Hire.class); Conclusion Javabeans are components to build applications Similar to chips in hardware Usually to build client applications Can be bought off the shelf Not distributed objects PropertyDescriptor pd2 = new PropertyDescriptor("department", Hire.class); pd2.setpropertyeditorclass( DepartmentEditor.class); return new PropertyDescriptor[] pd1, pd2; catch (Exception e) return null; Piet van Oostrum 20 Piet van Oostrum 21 Multi-tier applications Monolythic applications: The whole application is in one process This includes user interface, business logic and data handling Client-server applications Usually user-interface and business logic in client Database in server Multi-tier applications: Client contains only user interface Database server(s) Business logic in one or more intermediate tiers Enterprise Javabeans (EJB) EJB is a framework for multi-tier applications in Java Especially for the business logic tier This tier should concentrate on business objects customers students orders etc. The framework is responsible for providing services security transactions etc. Piet van Oostrum 22 Piet van Oostrum 23 slides9.pdf October 9, 2008 4

EJB advantages Cross-platform components (Java) Developer concentrates on Business programming, not services Scalable (business components can be divided over several servers) Can use existing services Database services Transaction services Web servers Security Multithreading,... EJB characteristics Some ideas from Javabeans EJB are server-side beans Communication through RMI or RMI-IIOP (hence Corba) EJB s work inside a container Containers run in a server Standards for communication between container and EJB Dynamic configuration through properties (environment) EJB s can be dynamically added to a server Client uses proxy object (EJB Object) Piet van Oostrum 24 Piet van Oostrum 25 EJB model EJB model Overview 23 Client Tier Web Browser Wireless Device Business Partner or Other System Applets, Applications, CORBA Clients IIOP Web services technologies (SOAP, UDDI, WSDL, ebxml) IIOP HTTP HTTP Firewall Servlets JSPs J2EE Server EJBs Servers e.g. JBoss, IBM Websphere, BEA WebLogic Connectors Back-End Systems JMS SQL Proprietary Protocol Web Services Technologies (SOAP, UDDI, WSDL, ebxml) Existing System Legacy System ERP System Business Partner or Other System Piet van Oostrum 26 Databases Piet van Oostrum Figure 1.6 A J2EE deployment. 27 EJB types (EJB version 2) Entity bean Corresponds to a (business) entity, e.g. customer, order, student Persistent object Survives server shutdown or crash Is loaded on demand (for scalability) Implements interface javax.ejb.entitybean Has primary key (e.g. order number, student number) Session bean Represents connection from a client Usually not persistent Implements interface javax.ejb.sessionbean Stateless or statefull Message-driven bean For messaging services (event driven) EJB container Java API for XML RPC (JAX-RPC). JAX-RPC is the main technology that provides support for developing Web Services on the J2EE platform. It defines two Web Service endpoint models one based on servlet technology and another based on EJB. It also specifies a lot of runtime requirements regarding the way Web Services should be supported in a J2EE runtime. Another specification called Web Services for J2EE defines deployment requirements for Web Services and uses the JAX-RPC programming model. Chapter 5 discusses support of Web Services provided by both these specifications for EJB applications. Container contains all the infrastructure (transactions etc.) EJB s relate to the world through the container For each EJB the container contains a Home object Java Remote Method Invocation (RMI) and RMI-IIOP. RMI is the Java language s native way to communicate between distributed objects, such as two different objects running on different machines. RMI-IIOP This is the factory object to create EJB s Every EJB class has its Home interface The interface contains methods to create, find (for entity beans), initialize,destroy beans Home interface extends javax.ejb.ejbhome EJB s are not directly called by clients Proxy EJB object is called instead Allows the container do supply services (transactions, persistence, etc.) Piet van Oostrum 28 Piet van Oostrum 29 slides9.pdf October 9, 2008 5

applications without writing to middleware APIs (see Figure 2.4). In outline, follow these steps to harness the power of middleware: 1. Write your distributed object to contain only business logic. Do not write to complex middleware APIs. For example, this is the code that would run inside the distributed object: Interceptors transfer(account account1, Account account2, long amount) // 1: Subtract the balance from one account, add to the other 2. Declare the middleware services that your distributed object needs in a separate descriptor file, such as a plain text file. For example, you might declare that you need transactions, persistence, and a security check. Client Remote Interface Remote Interface Distributed Object Request Interceptor Transaction API Security API Transaction Service Security Service EJBObject and Bean Client Code, such as Servlets or Applets 1: Call a Method 5: Return Result Remote Interface EJB Object 2: Call Middleware APIs 4: Method Returns 3: Call a Bean EJB Fundamentals 39 EJB Container/Server Transaction Service, Security Service, Persistence Sevice, etc Enterprise Bean Remote Interface Database API Database Driver Figure 2.5 EJB objects. Stub Network Skeleton The request interceptor knows what to do because you describe your needs in a special descriptor file. Piet Figure van 2.4 Oostrum Implicit middleware (gained through declarations). 30 Transactions Each EJB container ships with a suite of glue-code tools. These tools are meant to integrate beans into the EJB container s environment. The tools generate helper Java code stubs, skeletons, data access classes, and other classes that this specific container requires. Bean providers do not have to think about the specifics of how each EJB container works because the container s tools generate its own proprietary Java code automatically. The container s glue-code tools are responsible for transforming an enterprise Piet van Oostrum 31 bean into a fully managed, distributed server-side component. This involves logic to handle resource management, life cycle, state management, transactions, security, persistence, remote accessibility, and many other services. The generated code handles these services in the container s proprietary way. Transactions 2 Each container must implement interface javax.jts.usertransaction JTS = Java Transaction Service Some methods are: commit() rollback() EJB must have a transactional attribute that tells whether the bean supports and/or needs transactions Transaction can contain multiple EJB and/or Corba objects on multiple servers The Client Remote that Interface uses JNDI to locate beans use javax.jts.usertransaction As mentioned previously, bean clients invoke methods on EJB objects, rather than Corba the beans clients themselves. use Object Therefore, Transaction EJB objects Service must clone (OTS) every business method JTSthat is your the Java bean classes interface expose. to Corba s But how OTS do the tools that autogenerate EJB objects know which methods to clone? The answer is in a special interface that a RMI-IIOP bean provider is used writes. to communicate This interface duplicates with the OTS all the for business JNDI logic methods clients that the corresponding bean class exposes. This interface is called the remote interface. Remote interfaces must comply with special rules that the EJB specification defines. For example, all remote interfaces must derive from a common interface supplied by Sun Microsystems. This interface is called javax.ejb.ejbobject, and it is shown in Source 2.2. Piet van Oostrum 32 Piet van Oostrum 33 Client view Example Entity Bean Client has the Interface specification of the EJB Interface must be RMI compatible: extends EJBObject (extends Remote) methods must specify throws RemoteException Object parameters must be remote or serializable Client finds the EJB Home interface through the JNDI. It calls the Home interface with a create method to create a bean Implementation of the EJBObject methods is in the container Our entity bean needs the following: component interface (maybe remote and local) This is what clients need to know home interface (maybe remote/local) This is used to find/create entities implementation appropriate finder methods bean implementation class deployment descriptor Piet van Oostrum 34 Piet van Oostrum 35 slides9.pdf October 9, 2008 6

Component interface (local) We use an Employee entity as example import javax.ejb.*; import java.util.*; import java.sql.*; import java.math.*; public interface Employee extends javax.ejb.ejblocalobject public int getemployeeid(); public void setemployeename(string name); public String getemployeename(); public void setemployeeaddress(string address); public String getemployeeaddress(); public void setsalary(bigdecimal salary); public BigDecimal getsalary();... lots more... Remote Interface The remote interfaces must specify the throws RemoteException import javax.ejb.ejbobject; import java.ejb.remoteexception; public interface EmployeeRemote extends EJBObject public int getemployeeid() throws RemoteException; public void setemployeename(string firstname) throws RemoteException; public String getemployeename() throws RemoteException; public void setemployeeaddress(string lastname) throws RemoteException; public String getemployeeaddress() throws RemoteException;... get... and set... are for accessing instance variables (attributes) Piet van Oostrum 36 Piet van Oostrum 37 Home Interface More than one create() method is possible (overloaded) Only one findbyprimarykey is possible (must always have one parameter) import javax.ejb.ejbhome; import java.ejb.* // Exceptions public interface EmployeeHome extends EJBHome public Employee create(int employeeid, String name, String address) throws CreateException, RemoteException; public Employee findbyprimarykey( EmployeePrimaryKey empkey) throws FinderException, RemoteException; public class EmployeePrimaryKey implements Serializable public int employeeid; Entity Bean Persistence Persistence for Entity bean can be provided by: Container (container-managed persistence) At deployment time the deployer must give the container a list of fields that must be persisted Difficulities e.g. how do the fields map to database records? e.g. SQL code must be supplied (container dependent). Bean itself (bean-managed persistence) Bean must access database for persistence Or use another component to do the work Piet van Oostrum 38 Piet van Oostrum 39 Entity Context The container keeps a datastructure called EntityContext to keep info about the entity transaction, security, EJBObject, Primary key Important: the container can have more entities than instances of the EJB! The cantainer can reuse EJB s from a pool The EntityContext interface provides an instance with access to the container-provided context The container passes the EntityContext interface to an instance after the instance has been created. information that the instance obtains using the EntityContext interface (e.g result of getprimarykey()) may change. Example container-managed bean import javax.ejb.entitybean; import java.ejb.entitycontext; import java.ejb.createexception; public class EmployeeBean implements EntityBean private transient EntityContext entcontext; public int employeeid; public String employeename; public String employeeaddress; public void setentitycontext(entitycontext context) entcontext = context; Piet van Oostrum 40 Piet van Oostrum 41 slides9.pdf October 9, 2008 7

Example container-managed bean Example container-managed bean public void unsetentitycontext() entcontext = null; public EmployeePrimaryKey ejbcreate(int ID, String name, String address) throws CreateException employeeid = ID; employeename = name; employeeaddress = address; return null; public void ejbpostcreate(int ID, String name, String address) throws CreateException // This method is called by the container // after the persistence has be loaded public int getemployeeid() return this. employeeid; public void setemployeename(string empname) employeename = empname; // etc... Piet van Oostrum 42 Piet van Oostrum 43 Container Callable Methods Sequence diagram Create setentitycontext(entitycontext context): the entity bean must save the state of the EntityContext interface in its instance variable. unsetentitycontext(): container invokes this method before terminating the entity bean instance ejbcreate(): the signature of each one should map to the create() methods in the entity bean Home interface. ejbpostcreate(): For each ejbcreate() method provide matched ejbpostcreate() method. Called after the persistence has been loaded Client create() EJBHome ejbcreate() extract CMP fields create new DB entry EJBObject Instance database ejbpostcreate() Piet van Oostrum 44 Piet van Oostrum 45 Sequence diagrams Remove Client EJBHome EJBObject Instance database remove() ejbremove() remove from database Sequence diagrams Find (Container Managed Bean) Client EJBHome Instance database find<method> search database new EJBObject Piet van Oostrum 46 Piet van Oostrum 47 slides9.pdf October 9, 2008 8

Example client public class EmployeeTestClient private EmployeeHome employeehome = null; public EmployeeTestClient() try Context ctx = new InitialContext(); Object ref = ctx.lookup("employeeremote"); employeehome = (EmployeeHome) PortableRemoteObject.narrow (ref,employeehome.class); EmployeePrimaryKey empno = EmployeePrimaryKey(12345); EmployeeRemote employee = employeehome.findbyprimarykey (empno); System.out.println(employee.getEmployeeName()); System.out.println(employee.getEmployeeAddress()); catch(exception e) e.printstacktrace(); Piet van Oostrum 48 EJB version 2 complexities several interfaces and unnecessary callback methods. implementation of EJBObject or EJBLocalObject and many exceptions. container-managed persistence is complex. not really object-oriented (restrictions on inheritance and polymorphism). cannot test outside an EJB container. looking up an EJB is complex (JNDI). deployment descriptor is complex. Piet van Oostrum 49 EJB version 3 simplifications the bean class can be a plain java class (POJO) the EJB interface may be a pure interface (POJI) the EJB Home interface is no longer needed annotations can be used instead of a dedicated deployment descriptor annotations are metadata that are compiled into the class (can be obtained by the container with introspection) methods such as ejbpassivate, ejbactivate, ejbload, ejbstore not necessary to implement for all @Remote public interface EmployeeFacade Employee addemployee(string name, double salary); Employee findemployeebyempno(long empno); Piet van Oostrum 50 Example EJB3 Entity Bean @Entity @Table(name = "EMPLOYEES") public class Employee implements Serializable private int empid; private String Name; private double salary; @Id @Column(name="EMPNO", primarykey=true) public int getempid() return empid;... Piet van Oostrum 51 Example EJB3 Stateless Session Bean @Stateless public class EmployeeFacadeBean implements EmployeeFacade @PersistenceContext private EntityManager em; public Employee addemployee(string empname, double sal) Employee emp = new Employee(); emp.setname(empname); emp.setsal(sal); em.persist(emp); return emp; public Employee findemployeebyempno(long empno) return em.find(employee.class,empno); Piet van Oostrum 52 slides9.pdf October 9, 2008 9