You are on page 1of 40

EJB3.0 http://www.manning.

com/panda

RE: comparison between ejb2.0 and ejb3.0


The major differences i have seen between EJB 2.x and EJB 3.0 versions are as follows :-

1). Removal of home interface enabled simple lookup process in ejb 3.0

2). EJB deployment descriptors are not required in ejb3.0

3). Annotations are used in ejb3.0

4). EJB 3.0 entity beans don’t have home and remote interfaces.

5). EJB 3.0 entity beans/JPA becomes local. Remote annotations are not at all supported for entity
beans.

6). EJB 3.0 beans don’t implement the standard interfaces like javax.ejb.SessionBean and hence no
need to implement the container call back methods like ejbActivate() etc

7). Query is very flexible. Multiple levels of joins are enabled through the refined EJB-QL

8). Can be used with pluggable third party persistence providers

9). Security can be provided either through annotations or through deployment descriptors

10). POJO like EJB 3.0 entities become lightweight and easy to convert from a DAO to Entity bean
or vice versa. Since EJB 3 entities don’t need implement any interface.

I need more info on the following factors :-

1). Performance efficiency achieved by the removal of home interface deployment descriptor etc

2). container call back methods like ejbCreate() etc are eliminated. Then what about the
customised implementation possibility of session bean in ejb3.0?
ccvy
3). Is all the transaction attributes in ejb 3.0 are supported in ejb2.1?

4). REQUIRED - Start a new transaction if necessary

SUPPORTS - Don’t start a new transaction but use one if exists REQUIRESNEW – Always start a new
transaction suspending the old one MANDATORY - Require the caller to have started a transaction
NEVER - Forbid the caller to have started a transaction NOTSUPPORTED – Suspend any active
transaction

EJB or Enterprise Java Beans is a component architecture for


the development and deployment of object-oriented,
distributed, enterprise-level applications. Applications
written using the Enterprise JavaBeans architecture are
scalable, transactional, and multi-user and secure.

The
enterprise bean is a component that implements a business
task or business entity and is of two types- entity bean or
a session bean.

EJB vs hibernate
1)No container needed

2)No OOPS support,POJO support

Hibernate supports multi level cacheing, where as Entity Beans doesn't s

Entity beans are persistant objects which represents the


data stored in database.they are also know as database
interactive beans.we have 2 different types of entity beans.
1.cmp
2.bmp
SESSION BEANS are reusable components and contain the logic
for business process.they are usually associated with one
client.they are also called as client interactive beans.

EjbObject is an object which implements our component


interface.The container creats it when we call create
method on home stub.It contains business methods.It is a
beans body guard.

EJBs are server-side components. EJB are used to develop the distributed transactional and secure
applications based on Java technology.

EJB ia a server-side component architecture that simplifies the process of building enterprise-class
distributed application components in java.

Session bean is encapsulates the business logic. and carry out the task for behalf of the client. It
have two types.one is stateful session bean. this is maintain the convesional state.another one is
stateless session bean. donot maintain the conversional.state.

Stateless stateful

Scalable

Maintain state

Pooling,instance passivation passivation

Network traffic is more for stateless as moreparameters

One create methodf

List carrierList = new ArrayList();

carrierList.add(new LabelValueBean("UPS", "UPS"));

carrierList.add(new LabelValueBean("USPS", "USP"));

carrierList.add(new LabelValueBean("FedEx", "FDX"));


context.setAttribute("STRUTS_EXAMPLE_CARRIERS",carrierList);

<html:select property="address.state">

<html:options collection="STRUTS_EXAMPLE_STATES"

property="value"

labelProperty="label" />

</html:select>

Java Object: is a reusable component.


EJB : is a distributed component used to develop business applications. Container provides runtime
environment for EJBs.

Java Beans is intra-process component


where as EJB is an Inter-Process component
EJB is designed to work in distributed environment using rmi/iiop protocol where as JavaBean is
standalone and works only in the same JVM.

Implicit services are provided to EJb by the Container in which it si deployed according to EJB
contract but in JavaBean we need to code all these services

What is EJB

EJBs are ServerSide Business Components Used to encapsulate business logic without having to
worry about Application Developer

from System Level Issues( Trasaction Threading Distributable Security etc...)

Enterprise Java Bean is a specification for server-side scalable transactional and multi-user
secure enterprise-level applications. It provides a consistant component architecture for creating
distributed n-tier middleware

What is Session Bean

Session bean is encapsulates the business logic. and carry out the task for behalf of the client. It
have two types.one is stateful session bean. this is maintain the convesional state.another one is
stateless session bean. donot maintain the conversional.state

SFSB SLSB

Maintain client state across client request

Not scalable
No pooling

e) client specific data has to be pushed to the bean for each method invocation which result in
increase of network traffic.

Can have more than one create() method

Is

Whatis entity bean?

EB represent real data that stored in persistence store. Its objectoriented view of
persistencestore

More than that entity beans provide a component model that allows bean developers to focus their
attention on the business logic of the bean while the container takes care of managing
persistence transactions and access control

Session bean VS Entity Bean

Session beans are functional beans entity beans are value Beans

EjbObject is an object which implements our component


interface.The container creats it when we call create
method on home stub.It contains business methods.It is a
beans body guard.

sjbStore update the persistent storate with the updated values of the bean while ejbLoad get the
values from the database and set the properties of a bean. Container calls them intermediately to
keep the database consistent.

If i throw a custom ApplicationException from a


business method in Entity beanwhich is participating in a transaction, would the
transaction be rolled back by container. Does container rolls back transaction
only in case of SystemExceptions

We need to call explicitly.setRollback() Method to roll back the transaction in this. Container calls
this automatically in case of system exception or system crashes.

< The transaction attribute specifies how the Container must manage transactions for a
method when a client invokes the method via the enterprise bean?s home or component interface or
when the method is invoked as the result of the arrival of a JMS message. (Sun's EJB Specification)
Below is a list of transactional attributes:

Hashtable ht=new Hashtable();


ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");

ht.put(Context.PROVIDER_URL,"t3://localhost:7001");

InitialContext Context = new InitialContext(ht);

LoginHome
home=(LoginHome)Context.lookup("java:comp/env/ejb/LoginEJB");

How to refer other EJBs

<ejb-jar>

<enterprise-beans>

<session>

<ejb-name>SessionFacadeEJB</ejb-name>

<home>SessionFacade.SessionFacadeHome</home>

<remote>SessionFacade.SessionFacadeRemote</remote>

<ejb-class>SessionFacade.SessionFacadeBean</ejb-class>

<session-type>Stateful</session-type>

<transaction-type>Container</transaction-type>

<ejb-ref>

<ejb-ref-name>ejb/SavingsEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>

<home>savings.SavingsHome</home>

<remote>savings.SavingsRemote</remote>

</ejb-ref>

<ejb-ref>

<ejb-ref-name>ejb/CurrentEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>

<home>current.CurrentHome</home>

<remote>current.CurrentRemote</remote>

</ejb-ref>

<ejb-ref>

<ejb-ref-name>ejb/RecurringEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>
<home>recurring.RecurringHome</home>

<remote>recurring.RecurringRemote</remote>

</ejb-ref>

<ejb-ref>

<ejb-ref-name>ejb/LoginEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>

<home>login.LoginHome</home>

<remote>login.LoginRemote</remote>

</ejb-ref>

<ejb-ref>

<ejb-ref-name>ejb/TransEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>

<home>trans.TransHome</home>

<remote>trans.TransRemote</remote>

</ejb-ref>

</session>

</enterprise-beans>

<assembly-descriptor>

<container-transaction>

<method>

<ejb-name>SessionFacadeEJB</ejb-name>

<method-intf>Remote</method-intf>

<method-name>*</method-name>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

</assembly-descriptor>

</ejb-jar>

RE: What is the difference between JavaBean and EJB


JavaBeans- are reuseable non-deployable components. They can't exist independently.EJB - are
deployable reuesable server side components. They can exist independently or in integration with
other components.

isIdentical will return


always TRUE: for stateless session beans.
always false: for stateful session beans.
TRUE : for entity beans if they have the same primary key.

JavaBean :

1. Low-level approach for developing re-usable components for building different Java applications
(Applets stand-alone applications etc.).
2. Java Beans runs in a JVM just like other normal java class

EJB :

1. High-level approach to build Distributed java applications & its an Re-usable server-side
component

2. EJB runs under the control of EJB Container

JavaBean define a model for creating general-purpose components that are typically used on the
client side. Those components may or may not contain a user interface.

EJBs define a server-side component fro creating highly specialized business logic components.
EJB components don't have GUI.

A Java Bean is a software component that has been designed


to be reusable in a variety of different environments.

Reusable, deployable,client side

weblogic-cmp-rdbms-jar.xml

weblogic-ejb-jar.xml

<session>

<ejb-name>SessionFacadeEJB</ejb-name>
<home>SessionFacade.SessionFacadeHome</home>
<remote>SessionFacade.SessionFacadeRemote</remote>
<ejb-class>SessionFacade.SessionFacadeBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Container</transaction-type>
- <ejb-ref>
<ejb-ref-name>ejb/SavingsEJB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>savings.SavingsHome</home>
<remote>savings.SavingsRemote</remote>
</ejb-ref>
+ <ejb-ref>
+ <ejb-ref>
+ <ejb-ref>
+ <ejb-ref>
</session>

Ejb-jar.xml

- <ejb-jar>
- <enterprise-beans>
- <entity>
<ejb-name>SavingsEJB</ejb-name>
<home>savings.SavingsHome</home>
<remote>savings.SavingsRemote</remote>
<ejb-class>savings.SavingsBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
- <cmp-field>
<field-name>accno</field-name>
</cmp-field>
- <cmp-field>
<field-name>acctype</field-name>
<query>

<query-method>

<method-name>findBigClubs</method-name>

<method-params>

<method-param>int</method-param>

</method-params>

</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM FanClubEJB AS a WHERE a.memberCount >= ?1]]>

</ejb-ql>

</query>

<ejb-ref>

<ejb-ref-name>ejb/SavingsEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>

<home>savings.SavingsHome</home>
<remote>savings.SavingsRemote</remote>

</ejb-ref>

<ejb-ref>

<ejb-ref-name>ejb/CurrentEJB</ejb-ref-name>

<ejb-ref-type>Entity</ejb-ref-type>

<home>current.CurrentHome</home>

<remote>current.CurrentRemote</remote>

</ejb-ref>
</enterprise-beans>

<relationships>

<ejb-relation>

<ejb-relation-name>Band-Recording</ejb-relation-name>

<ejb-relationship-role>

<ejb-relationship-role-name>

Band-Has-Recordings

</ejb-relationship-role-name>

<multiplicity>one</multiplicity>

<relationship-role-source>

<ejb-name>BandEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>recordings</cmr-field-name>

<cmr-field-type>java.util.Set</cmr-field-type>

</cmr-field>

</ejb-relationship-role>

<ejb-relationship-role>

<ejb-relationship-role-name>

Recording-Has-Band

</ejb-relationship-role-name>

<multiplicity>many</multiplicity>

<relationship-role-source>

<ejb-name>RecordingEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>band</cmr-field-name>

</cmr-field>

</ejb-relationship-role>
</ejb-relation>

<?xml version="1.0" ?>


<!DOCTYPE weblogic-ejb-jar (View Source for full doctype...)>
- <weblogic-ejb-jar>
- <weblogic-enterprise-bean>
<ejb-name>SavingsEJB</ejb-name>
- <entity-descriptor>
- <persistence>
- <persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>7.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-use>
</persistence>
</entity-descriptor>
<jndi-name>savings.SavingsHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

Weblogic-cmp-rdbms-jar.sml

weblogic-rdbms-jar>
- <weblogic-rdbms-bean>
<ejb-name>SavingsEJB</ejb-name>
<data-source-name>AdiPool</data-source-name>
- <table-map>
<table-name>savings</table-name>
<- <field-map>
< cmp-field>accno</cmp-field>
<dbms-column>accno</dbms-column>
</field-map>

Transaction

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Converter</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
</assembly-descriptor>

CMP VS BMP

1.code reduction,Rapid application Development


2.CMP hard to debug, lack of control

3. application server, Database server independence, but in BMP jdbc specific code is written

4. provides relationship b/w entity beans, instead of manullay wrote spegate code

5. learinng curve-> BMP favours

Complex queries might not be possible with the basic EJBQL for CMPs.So prefer BMPs for complex
queries.

Container will tyr to optimize the SQL code for the CMPs so they may be scalable entity beans than
the BMPs.

: What are advantages and disadvantages of CMP and BMP


CMP::

Advantages:
1)Easy to develop and maintain.
2)Relationships can be maintained between different entities.
3)Optimization of SQL code will be done.
4)Larger and more performance applications can be done.

Disadvantages:

1)Will not support for some nonJDBC data sources i.e CICS.
2)Complex queries cannot be developed with EJBQL.

BMP::

Advantages:
1)Support for nonJDBC data sources.
2)Complex queries can be build.

Disadvantages:

1)Hard to develop and maintain.


2)We cannot maintain the relationships between different entities.
3)Optimization of SQL code cannot be done by the container because bean it self contains the
code.
4)Not appropriate for larger and complex applications.

CMP VS BMP

1)JdbcCode writing

2)complex queries ccan’t be write in EJB-QL

3)support only Jdbc persistence

4) For CMP beans you can map only one table at a time. But for BMP u can map more that one
table at a time.

RE: What is the need of two Objects i.e EJBHome object...


In order to achieve the location transperancy we need two objects
since bean objects are not remote objects ejb object delegates client request to the bean object
we have to create ejb objects on client arrival only then we haveto send ejb object reference to
client so we are giving chance to know the location of program so we need another object that is
home object this home object is a factory of ejb objects this home object is created once when
ejb component is deployed here also a possibility to know the location of server program so we
require jndi services jndiname is a nickname given by naming services so we have to bind home
object reference with that reference.

CMP relationship examples

<relationships>

<ejb-relationship-role>

< ejb-relationship-role-name></ ejb-relationship-role-name>

<multiplicity>

< ejb-relationship-role-spurce>

<ejb-name>

</ ejb-relationship-role-spurce>

<cmp-field>

<cmp-field-name>

</cmp-field-type>

</cmp-field>

</ejb-relationship-role>

A design pattern describes a recurring desing problem and a core solution to it.

Bestsolution to reccuring problems

Select->ejjbSelect

Update->get,set methods

Delete-> remove()\
Insert-> ejbCreate

RE: why we need the transactions?


Txns is a unit of work which guaranties about it's execution.

Objects returned by looking up a JNDI Name are returned by RMI-IIOP protocol. Since this
protocol is language independent objects returned by it should be typecasted using RMI-IIOP
compliant method. Therefore we use PortableRemoteObject.narrow()

Messsagedrivansen bean

<enterprise-beans>

<messaage-driven-destination>

<destination-type>javax.jms.Topic

</message-driven-destination>

<message-drinven>

</message-friv

Complete ejb –jar.xml

<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC

'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'

'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>

<ejb-jar>

<enterprise-beans>

<session>

<ejb-name>MusicLibraryEJB</ejb-name>

<home>examples.ejb20.relationships.bands.MusicLibraryHome</home>

<remote>examples.ejb20.relationships.bands.MusicLibrary</remote>

<ejb-class>examples.ejb20.relationships.bands.MusicLibraryBean</ejb-
class>
<session-type>Stateless</session-type>

<transaction-type>Container</transaction-type>

</session>

<entity>

<ejb-name>BandEJB</ejb-name>

<local-home>examples.ejb20.relationships.bands.BandHome</local-home>

<local>examples.ejb20.relationships.bands.Band</local>

<ejb-class>examples.ejb20.relationships.bands.BandBean</ejb-class>

<persistence-type>Container</persistence-type>

<prim-key-class>examples.ejb20.relationships.bands.BandPK</prim-key-
class>

<reentrant>False</reentrant>

<cmp-version>2.x</cmp-version>

<abstract-schema-name>BandEJB</abstract-schema-name>

<cmp-field>

<field-name>name</field-name>

</cmp-field>

<cmp-field>

<field-name>founder</field-name>

</cmp-field>

<cmp-field>

<field-name>startDate</field-name>

</cmp-field>

<query>

<query-method>

<method-name>findByName</method-name>

<method-params>

<method-param>java.lang.String</method-param>

</method-params>
</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM BandEJB AS a WHERE a.name = ?1]]>

</ejb-ql>

</query>

<query>

<query-method>

<method-name>findAll</method-name>

<method-params>

</method-params>

</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM BandEJB AS a]]>

</ejb-ql>

</query>

</entity>

<entity>

<ejb-name>RecordingEJB</ejb-name>

<local-home>examples.ejb20.relationships.bands.RecordingHome</local-
home>

<local>examples.ejb20.relationships.bands.Recording</local>

<ejb-class>examples.ejb20.relationships.bands.RecordingBean</ejb-class>

<persistence-type>Container</persistence-type>

<prim-key-class>examples.ejb20.relationships.bands.RecordingPK</prim-
key-class>

<reentrant>False</reentrant>

<cmp-version>2.x</cmp-version>

<abstract-schema-name>RecordingEJB</abstract-schema-name>
<cmp-field>

<field-name>title</field-name>

</cmp-field>

<cmp-field>

<field-name>bandName</field-name>

</cmp-field>

<cmp-field>

<field-name>bandFounder</field-name>

</cmp-field>

<cmp-field>

<field-name>sales</field-name>

</cmp-field>

<cmp-field>

<field-name>numberSold</field-name>

</cmp-field>

<cmp-field>

<field-name>recordingDate</field-name>

</cmp-field>

<query>

<query-method>

<method-name>findBigRecordings</method-name>

<method-params>

<method-param>long</method-param>

</method-params>

</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM RecordingEJB AS a WHERE


a.numberSold > ?1]]>

</ejb-ql>
</query>

<query>

<query-method>

<method-name>findByTitle</method-name>

<method-params>

<method-param>java.lang.String</method-param>

</method-params>

</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM RecordingEJB AS a WHERE a.title = ?


1]]>

</ejb-ql>

</query>

<query>

<query-method>

<method-name>findNotByBand</method-name>

<method-params>

<method-param>examples.ejb20.relationships.bands.Band</method-
param>

</method-params>

</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM RecordingEJB AS a WHERE a.band <>


?1]]>

</ejb-ql>

</query>

</entity>

<entity>
<ejb-name>FanClubEJB</ejb-name>

<local-home>examples.ejb20.relationships.bands.FanClubHome</local-
home>

<local>examples.ejb20.relationships.bands.FanClub</local>

<ejb-class>examples.ejb20.relationships.bands.FanClubBean</ejb-class>

<persistence-type>Container</persistence-type>

<prim-key-class>examples.ejb20.relationships.bands.FanClubPK</prim-key-
class>

<reentrant>False</reentrant>

<cmp-version>2.x</cmp-version>

<abstract-schema-name>FanClubEJB</abstract-schema-name>

<cmp-field>

<field-name>bandName</field-name>

</cmp-field>

<cmp-field>

<field-name>bandFounder</field-name>

</cmp-field>

<cmp-field>

<field-name>text</field-name>

</cmp-field>

<cmp-field>

<field-name>memberCount</field-name>

</cmp-field>

<query>

<query-method>

<method-name>findBigClubs</method-name>

<method-params>

<method-param>int</method-param>

</method-params>
</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(a) FROM FanClubEJB AS a WHERE


a.memberCount >= ?1]]>

</ejb-ql>

</query>

<query>

<query-method>

<method-name>ejbSelectAfterDateExcludeBand</method-name>

<method-params>

<method-param>java.sql.Date</method-param>

<method-param>examples.ejb20.relationships.bands.Band</method-
param>

</method-params>

</query-method>

<ejb-ql>

<![CDATA[SELECT OBJECT(r) FROM FanClubEJB as f, r in f.band.recordings

WHERE r.recordingDate >= ?1 AND f.band <> ?2]]>

</ejb-ql>

</query>

</entity>

<entity>

<ejb-name>ArtistEJB</ejb-name>

<local-home>examples.ejb20.relationships.bands.ArtistHome</local-home>

<local>examples.ejb20.relationships.bands.Artist</local>

<ejb-class>examples.ejb20.relationships.bands.ArtistBean</ejb-class>

<persistence-type>Container</persistence-type>

<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>

<cmp-version>2.x</cmp-version>

<cmp-field>

<field-name>id</field-name>

</cmp-field>

<cmp-field>

<field-name>name</field-name>

</cmp-field>

<primkey-field>id</primkey-field>

</entity>

</enterprise-beans>

<relationships>

<ejb-relation>

<ejb-relation-name>Band-Recording</ejb-relation-name>

<ejb-relationship-role>

<ejb-relationship-role-name>

Band-Has-Recordings

</ejb-relationship-role-name>

<multiplicity>one</multiplicity>

<relationship-role-source>

<ejb-name>BandEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>recordings</cmr-field-name>

<cmr-field-type>java.util.Set</cmr-field-type>

</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role>

<ejb-relationship-role-name>

Recording-Has-Band

</ejb-relationship-role-name>

<multiplicity>many</multiplicity>

<relationship-role-source>

<ejb-name>RecordingEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>band</cmr-field-name>

</cmr-field>

</ejb-relationship-role>

</ejb-relation>

<ejb-relation>

<ejb-relation-name>Band-FanClub</ejb-relation-name>

<ejb-relationship-role>

<ejb-relationship-role-name>

Band-Has-FanClub

</ejb-relationship-role-name>

<multiplicity>one</multiplicity>

<relationship-role-source>

<ejb-name>BandEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>fanClub</cmr-field-name>

</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role>

<ejb-relationship-role-name>

FanClub-Has-Band

</ejb-relationship-role-name>

<multiplicity>one</multiplicity>

<cascade-delete/>

<relationship-role-source>

<ejb-name>FanClubEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>band</cmr-field-name>

</cmr-field>

</ejb-relationship-role>

</ejb-relation>

<ejb-relation>

<ejb-relation-name>Band-Artist</ejb-relation-name>

<ejb-relationship-role>

<ejb-relationship-role-name>

Bands-Have-Artists

</ejb-relationship-role-name>

<multiplicity>many</multiplicity>

<relationship-role-source>

<ejb-name>BandEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>artists</cmr-field-name>
<cmr-field-type>java.util.Set</cmr-field-type>

</cmr-field>

</ejb-relationship-role>

<ejb-relationship-role>

<ejb-relationship-role-name>

Artists-Have-Bands

</ejb-relationship-role-name>

<multiplicity>many</multiplicity>

<relationship-role-source>

<ejb-name>ArtistEJB</ejb-name>

</relationship-role-source>

<cmr-field>

<cmr-field-name>bands</cmr-field-name>

<cmr-field-type>java.util.Set</cmr-field-type>

</cmr-field>

</ejb-relationship-role>

</ejb-relation>

</relationships>

<assembly-descriptor>

<container-transaction>

<method>

<ejb-name>MusicLibraryEJB</ejb-name>

<method-name>*</method-name>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>
<container-transaction>

<method>

<ejb-name>BandEJB</ejb-name>

<method-name>*</method-name>

</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

<container-transaction>

<method>

<ejb-name>FanClubEJB</ejb-name>

<method-name>*</method-name>

</method>

<trans-attribute>Supports</trans-attribute>

</container-transaction>

<container-transaction>

<method>

<ejb-name>ArtistEJB</ejb-name>

<method-name>*</method-name>

</method>

<trans-attribute>Supports</trans-attribute>

</container-transaction>

<container-transaction>

<method>

<ejb-name>RecordingEJB</ejb-name>

<method-name>*</method-name>
</method>

<trans-attribute>Required</trans-attribute>

</container-transaction>

</assembly-descriptor>

<ejb-client-jar>ejb20_relationships_bands_client.jar</ejb-client-jar>

</ejb-jar>

http://www.gorecroot.com/Questionpaper/javaejb.aspx

1. What is EJB?

2. What is session Facade?

a)tight coupling, client needs to directly interact with business beans. AS client
requirement grows client need to take care of

transaction demarcations, inter relationship grows between beans.

b) network traffic, too many remote calls if we allow direct interaction with Ejb
business beans

c) Workflow is handled in cliet side which should avoided.

d) Direct dependence means that the client must represent and implement the complex
interactions regarding business object lookups

and creations, and must manage the relationships between the participating business
objects as well as understand the

responsibility of transaction demarcation.


Forces

• Provide a simpler interface to the clients by hiding all the complex interactions
between business components.
• Reduce the number of business objects that are exposed to the client across the service
layer over the network.
• Hide from the client the underlying interactions and interdependencies between
business components. This provides better manageability, centralization of
interactions (responsibility), greater flexibility, and greater ability to cope with
changes.
• Provide a uniform coarse-grained service layer to separate business object
implementation from business service abstraction.
• Avoid exposing the underlying business objects directly to the client to keep tight
coupling between the two tiers to a minimum.

3. What is EJB role in J2EE?

4. What is the difference between EJB and Java beans?

5. What are the key features of the EJB technology?

6. What are the key benefits of the EJB technology?

1. EJB components are server-side components written entirely in the Java


programming language
2. EJB components contain business logic only - no system-level programming &
services, such as transactions, security, life-cycle, threading, persistence, etc.
are automatically managed for the EJB component by the EJB server.
3. EJB architecture is inherently transactional, distributed, portable multi-tier,
scalable and secure.
4. EJB components are fully portable across any EJB server and any OS.
5. EJB architecture is wire-protocol neutral--any protocol can be utilized like
IIOP,JRMP, HTTP, DCOM,etc.

7. How many enterprise beans?

8. What is message-driven bean?

9. What are Entity Bean and Session Bean?

10. How EJB Invocation happens?

11. Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the
HttpSession from inside an EJB?

12. The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client,
does the container create a separate instance of the generated EJBHome and EJBObject classes?

13. Can the primary key in the entity bean be a Java primitive type such as int?

14. Can you control when passivation occurs?


15. What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database
operations? When would I use one over the other?

16. What is EJB QL?

17. Brief description about local interfaces?

18. What are the special design cares that must be taken when you work with local interfaces?

19. What happens if remove( ) is never invoked on a session bean?

20. What is the difference between Message Driven Beans and Stateless Session beans?

22. How can I call one EJB from inside of another EJB?

23. What is an EJB Context?

24. Is it possible for an EJB client to marshal an object of class java.lang.Class to an EJB?

25. Is it legal to have static initializer blocks in EJB?

26. Is it possible to stop the execution of a method before completion in a SessionBean?

27. What is the default transaction attribute for an EJB?

28. What is the difference between session and entity beans? When should I use one or the other?

29. Is there any default cache management system with Entity beans?

30. Why is ejbFindByPrimaryKey mandatory?

31. Why do we have a remove method in both EJBHome and EJBObject?

32. How can I call one EJB from inside of another EJB?=

33. What is the difference between a Server, a Container, and a Connector?

34. How is persistence implemented in enterprise beans?

35. What is an EJB Context?

36. Is method overloading allowed in EJB?

37. Are we allowed to change the transaction isolation property in middle of a transaction?

38. For Entity Beans, What happens to an instance field not mapped to any persistent storage, when the bean is
passivated?

39. What is a Message Driven Bean, what functions does a message driven bean have and how do they work in
collaboration with JMS?

40. Does RMI-IIOP support code downloading for Java objects sent by value across an IIOP connection in the same
way as RMI does across a JRMP connection?

41. Does the container create a separate instance of the generated EJBHome and EJBObject classes?

42. What is the advantage of putting an Entity Bean instance from the Ready State to Pooled State?
43. What is the need of Remote and Home interface. Why can’t it be in one?

44. Can I develop an Entity Bean without implementing the create() method in the home interface?

45. Why an onMessage call in Message-driven bean is always a separate transaction?

46. Why are ejbActivate() and ejbPassivate() included for stateless session bean even though they are never required
as it is a no conversational bean?

47. Static variables in EJB should not be relied upon as they may break in clusters. Why?

48. If I throw a custom ApplicationException from a business method in Entity bean which is participating in a
transaction, would the transaction be rolled back by container?

49. Does Stateful Session bean support instance pooling?

50. Can I map more than one table in a CMP?

51. Can I invoke Runtime.gc() in an EJB?

52. Can a Session Bean be defined without ejbCreate() method?

53. How to implement an entity bean which the PrimaryKey is an auto numeric field?

54. When defining the Primary Key for the Enterprise Bean, the Deployer using the Container Provider's tools will
typically add additional container-managed fields to the concrete subclass of the entity bean class.

55. What is clustering?

56. Is it possible to share an HttpSession between a JSP and EJB?

57. If my session bean with single method insert record into 2 entity beans, how can know that the process is done in
same transaction (the attributes for these beans are Required)?

58. When should I adopt BMP and when I should use CMP?

1) What's different in Enterprise JavaBeans 1.1?

2)What is Enterprise JavaBeans?

3) What is an enterprise bean?

4) Are Enterprise JavaBeans and JavaBeans the same thing?

5) How does passivation work in stateful session beans?

6) How does a client application create a transaction object?

7) Do JTS implementations support nested transactions?

8) Why would a client application use JTA transactions?

9) How does a session bean obtain a JTA UserTransaction object?

10) Why would a session bean use bean-managed transactions?

11) How does an enterprise bean that uses container-managed transactions obtain a JTA UserTransaction object?
12) Is it possible for a stateless session bean to employ a JTA UserTransaction object?

13) How do you configure a session bean for bean-managed transactions?

14) How does an entity bean obtain a JTA UserTransaction object?

15) Is it necessary for an entity bean to protect itself against concurrent access from multiple transactions?

16) What are the constraints or drawbacks of container managed EJB's ?

17) Is entity data persisted at the end of a transaction or at any time?

18) How do enterprise beans access native libraries?

19) How do I implement a logging system in my beans?

20) What is a container?

21) What makes a Java class an enterprise bean?

22) While deploying CMP entity beans, which fields in the bean are container-managed and how are they identified?

23) Does the EJB programming model support inheritance?

24) How should complex find operations be implemented?

25) Can I use Threads in a enterprise bean?

26) Why are beans not allowed to create their own threads?

27) How does EJB support polymorphism?

28) What classes does a client application need to access EJB?

29) What is an EJB primary key? How is it implemented when the database doesn't have a primary key?

30) What's an .ear file?

31) Can beans use stored procedures in a database?

32) Is method overloading allowed in EJB?

33) How can JMS be used from EJB 1.1?

34) Can primary keys contain more than one field?

35) How does Container Managed Persistence work with automatically generated database

ID fields? Should I map the ID field explicitly or leave it unspecified?

36) Let's assume I use a JavaBean as a go-between a JSP and an EJB, and have, say, 50 concurrent clients that need
to access the EJB functionality. Will the JSP container actually instantiate 50 instances of the bean, or can it reuse a
single instance to access the EJB?

37) What happens when two users access an Entity Bean concurrently?
38) What's the reason for having two interfaces -- EJBHome for creating, finding & removing and EJBObject for
implementing business methods. Why not have an single interface which supports both areas of functionality?

39) Which fields in beans should be public?

40) How do you implement callbacks in EJB?

41) When should I use bean-managed transactions instead of specifying transaction information in the deployment
descriptor?

42) How do I automatically generate primary keys?

43) How is the passivation of Entity beans Managed?

44) To complete a transaction, which Transaction Attributes or Isolation Level should be used for a stateless session
bean?

45) Explain the different Transaction Attributes and Isolation Levels with reference to a scenario.

46) What is the most efficient approach for integrating EJB with JSP? Should the EJBs be invoked directly from
within JSP scriptlets? Should the access take place from within Java beans? Or is it best to use custom tags for this
purpose?

47) How do you get a JDBC database registered with a JNDI name so that it can be accessed from an EJB?

48) How to manage fields that can have null values in a container-managed Entity bean?

49) How can I debug my EJB applications?

50) How can an applet talk directly with EJB?

51) What is the best way of implementing a web application that uses JSP, servlet and EJB technologies all together
following a Model View Controller (MVC) architecture?

52) When does the container call my bean's ejbCreate / ejbPostCreate / ejbStore / ejbPassivate / ejbActivate /
ejbLoad / ejbPassivate method? And what should I do inside it?

53) What's the difference between EJBHome, EJB Home, EJB Object, EJBObject and EJB (not to mention Home
Interface and Remote Interface)?

54) Is there a difference between container managed and bean managed persistence in terms of performance?

55) Given that RMI-IIOP does not support distributed garbage collection (unlike RMI-JRMP), do I need to do
something explicitly to GC beans, or is it magically handled by the EJB framework?

56) OK, so EJB doesn't support user-created threads. So how do I perform tasks asynchronously?

57) What is an EJB Context?

58) Can I deploy a new EJB without restarting my server? (I'm using Weblogic.)

59) How to setup access control in an EJB such that different application clients have different rights to invoke
different methods in one EJB?

60) How is persistence implemented in enterprise beans?

61) Can the primary key in the entity bean be a Java primitive type such as int?
62) How do I map a Date/Time field to an Oracle database with CMP?

63) What is the difference between a Server, a Container, and a Connector?

64) What is "clustering" in EJB?

65) What is "hot deployment" in WebLogic?

66) Can I specify specific WHERE clauses for a find method in a CMP Entity Bean?

67) When using a stateful session bean with an idle timeout set, how can the bean receive notification from the
container that it is being removed due to timeout?

68) I have created a remote reference to an EJB in FirstServlet. Can I put the reference in a servlet session and use
that in SecondServlet?

69) What is the difference between a Component Transaction Monitor (CTM) and an Application Server?

70) How can I call one EJB from inside of another EJB?

71) When using Primary Keys, why do I have to implement the hashCode() and equals() method in my bean?

72) Can I deploy two beans in a single jar file? If so, how?

73) Why use EJB when we can do the same thing with servlets?

74) What restrictions are imposed on an EJB? That is, what can't an EJB do?

75) Why do we have a remove method in both EJBHome and EJBObject?

76) Why is it that business methods should not be declared final?

77) Why is ejbFindByPrimaryKey mandatory?

78) How can I pass init parameters to enterprise beans?

79) Should I use CMP or BMP for an application with complex data manipulation & relations?

80) For session beans, we can use the SessionSynchronization interface. For entity beans, how do we have control
over a transaction?

can you please tell me about the use of marker interface?

Ans: Marker or taged interfaces having no methods.example


Cloneable,Serializable etc.Actually this interfaces give
some infermation about a object.that means internally it
check the object wheather it belongs to that interface or
not,using instanceOf() methd.

Q4)What is difference between HashMap and HashTable?


Ans) Both collections implements Map. Both collections store value as key-value pairs. The
key differences between the two are

1. Hashmap is not synchronized in nature but hshtable is.

2. Another difference is that iterator in the HashMap is fail-safe while the enumerator for the
Hashtable isn't.
Fail-safe - “if the Hashtable is structurally modified at any time after the iterator is
created, in any way except through the iterator's own remove method, the iterator will throw a
ConcurrentModificationException†(Runtime exception )

3. HashMap permits null values and only one null key, while Hashtable doesn't allow key or
value as null.

Subclasses of java.lang.Exception are recommended for communicating errors between


tiers. In a distributed environment, such exception classes must be serializable so that they
can move across tier boundaries.

Handling Exceptions

The exceptions thrown by enterprise beans fall into two categories: system and application.

A system exception indicates a problem with the services that support an application.
Examples of these problems include the following: a database connection cannot be obtained,
a SQL insert fails because the database is full, or a lookup method cannot find the desired
object. If your enterprise bean encounters a system-level problem, it should throw a
javax.ejb.EJBException. The container will wrap the EJBException in a
RemoteException, which it passes back to the client. Because the EJBException is a
subclass of the RuntimeException, you do not have to specify it in the throws clause of the
method declaration. If a system exception is thrown, the EJB container might destroy the
bean instance. Therefore, a system exception cannot be handled by the bean's client program;
it requires intervention by a system administrator.

An application exception signals an error in the business logic of an enterprise bean. There
are two types of application exceptions: customized and predefined. A customized exception
is one that you've coded yourself, such as the InsufficentBalanceException thrown by the
debit business method of the SavingsAccountEJB example. The javax.ejb package
includes several predefined exceptions that are designed to handle common problems. For
example, an ejbCreate method should throw a CreateException to indicate an invalid
input parameter. When an enterprise bean throws an application exception, the container does
not wrap it in another exception. The client should be able to handle any application
exception it receives.
If a system exception occurs within a transaction, the EJB container rolls back the
transaction. However, if an application exception is thrown within a transaction, the container
does not roll back the transaction.

Table 5-2 summarizes the exceptions of the javax.ejb package. All of these exceptions are
application exceptions, except for the NoSuchEntityException and the EJBException,
which are system exceptions.

Logging

http://www.ibm.com/developerworks/java/library/j-ejbexcept.html

Additionally, log4j allows logging to be controlled on a class-by-class basis, whereas


System.out can only be controlled at the granularity of the entire application (if you redirect
System.out, you redirect it for the entire program).

Appendars, level, threshold severioty can be decided by app dev.

And while System.out can be redirected, this redirection tends to be fairly limited; System.out
can be redirected to a file or to a pipe (to another program), but you wouldn't be able to
redirect it to a URL, for example; by contrast, it would be very easy to create an appender
that transmits logging messages using HTTP POST.

loggers, appenders and layouts.

Trace< DEBUG < INFO < WARN < ERROR < FATAL.

Currently, appenders exist for the console, files, GUI components, remote socket servers,
JMS, NT Event Loggers, and remote UNIX Syslog daemons. It is also possible to log
asynchronously.

Note that by default, the root logger is assigned to Level.DEBUG.

This significantly increases performance and reduces log4j's memory footprint.

http://logging.apache.org/log4j/1.2/manual.html

log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# Print the date in ISO 8601 format


log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

# Print only messages of level WARN or above in the package com.foo.


log4j.logger.com.foo=WARN
Named Hierarchy
A logger is said to be an ancestor of another logger if its name followed by a dot is a
prefix of the descendant logger name. A logger is said to be a parent of a child logger
if there are no ancestors between itself and the descendant logger.
Basic Selection Rule
A log request of level p in a logger with (either assigned or inherited, whichever is
appropriate) level q, is enabled if p >= q.
// get a logger instance named "com.foo"
Logger logger = Logger.getLogger("com.foo");

// Now set its level. Normally you do not need to set the
// level of a logger programmatically. This is usually done
// in configuration files.
logger.setLevel(Level.INFO);

Logger barlogger = Logger.getLogger("com.foo.Bar");

// This request is enabled, because WARN >= INFO.


logger.warn("Low fuel level.");

// This request is disabled, because DEBUG < INFO.


logger.debug("Starting search for nearest gas station.");

// The logger instance barlogger, named "com.foo.Bar",


// will inherit its level from the logger named
// "com.foo" Thus, the following request is enabled
// because INFO >= INFO.
barlogger.info("Located nearest gas station.");

// This request is disabled, because DEBUG < INFO.


barlogger.debug("Exiting gas station search");

Suppose we are no longer interested in seeing the output of any component belonging to the
com.foo package. The following configuration file shows one possible way of achieving this.

# Print only messages of level WARN or above in the package com.foo.


log4j.logger.com.foo=WARN

An onMessage call is always a separate transaction, because there is never a transaction in


progress when the method is called."

The container invokes a message driven bean method


with its transaction attribute set to Required with a
valid transaction context. Since there is no client
transaction context available for a message-driven
bean, the container automatically starts a new
transaction before the dequeuing of the JMS message
which is before the invocation of the onMessage
method. The container automatically enlists the
resource manager associated with the arriving message
and all the resource managers accessed by the
onMessage method with the transaction. If the
onMessage method invokes other enterprise beans, the
container propagates the transaction context with the
invocation. Finally, it attempts to commit the
transaction when the onMessage method has completed.
In case the onMessage method does not successfully
complete, the transaction is rolled back by the
container and typical JMS message redelivery semantics
apply.
What is Instance pooling?
Article Number: 21738 | Last Updated: Sat, Dec 26, 2009 at 12:25 PM

For SingleThreadModel servlets, containers may follow one of the following approaches to ensure that each
sevlet instance is invoked in a separate thread:

Instance Pooling :
in this approach, the container maintains a pool of servlet instances. For each incoming request, the
container allocates a servlet instance from the pool, and upon completion of the service, the container
returns the instance to the pool.

Request Serialization :
in this approach, the container maintains a single instance of the servlet. However since the container
cannot send multiple requests to the instance at the same time, the container serialize the requests. This
means that new requests will be kept waiting while the current request is being served.

a combination of these two approaches is more pragmatic, so that the container could maintain a
reasonable member of instances in the pool, while still serializing requests if the number of requests
exceeds the number of instance in the pool.

What are advantages and disadvantages of CMP and BMP


Article Number: 21916 | Last Updated: Sat, Dec 26, 2009 at 2:28
PM

CMP::

Advantages:
1)Easy to develop and maintain.
2)Relationships can be maintained between different entities.
3) Optimization of SQL code will be done.
4)Larger and more performance applications can be done.

Disadvantages:

1)Will not support for some nonJDBC data sources,i.e,CICS.


2)Complex queries cannot be developed with EJBQL.

BMP::

Advantages:
1)Support for nonJDBC data sources.
2)Complex queries can be build.
Disadvantages:

1)Hard to develop and maintain.


2)We cannot maintain the relationships between different entities.
3)Optimization of SQL code cannot be done by the container,because bean it self
contains the code.
4)Not appropriate for larger and complex applications.

Optimistic Locking

Is based on the assumption that it is unlikely that separate users will access the same object
simultaneously. The EJB does not hold a lock for the duration of the transaction just for the small
period of time the EJB interacts with the DB. If db detects a collision the transaction rolls back.
Suitable for large systems requiring significant concurrent access.

Pessimistic locking:

The EJB holds a lock for the duration of the transaction not allowing any other updates to the data.
Suitable for small scale system where concurrent access is
rare.

http://www.1000projects.com/software/java-related/ejb-interview-questions.htm

http://www.1000projects.com/software/java-related/hibernate-interview-questions.htm

Is there a way to get the original exception object from inside a nested or
wrapped Exception (for example an EJBException or RemoteException
Article Number: 21575 | Last Updated: Sat, Dec 26, 2009 at 11:23 AM

Yes.
The way to get, depends on the Exception, since there are no standards. Some
examples:

* When we have an javax. ejb.EJBException, we can use the


getCausedByException() that returns a java. lang.Exception.

* A java.rmi.RemoteException there is a public field called detail of type


java.lang.Throwable

* With a java. sql.SQLException we need to use the method getNextException() to


get the chained java.sql.SQLException.

* When we have an java.lang.reflect.InvocationtargetException, we can get the


thrown target java.lang.Throwable using the getTargetException() method.

Entity beans are the only one bean that is reentrant. Neither Session bean
nor Message Driven Bean are reentrant. When Entity bean, we have to declare in the
deployment descriptor whether it is reentrant ( true or false).
Can I develop an Entity Bean without implementing the create() method in the
home interface
Article Number: 21597 | Last Updated: Sat, Dec 26, 2009 at 11:30 AM

Yes, you can create entity bean without impelementing the create() method. The ejbs will be instantiated
by findByPK or any finder methods

http://www.coolinterview.com/type.asp?iType=32

Although for Stateful Session Beans, the container cannot passivate an instance that is
inside a transaction. So using transactions can be a a strategy to control passivation.
What is the lifecycle of Entity Bean

Answers:

The following steps describe the life cycle of an entity bean instance

An entity bean instances life starts when the container creates the instance using
newInstance and then initialises it using setEntityContext.

The instance enters the pool of available instances. Each entity bean has its own pool.
While the instance is in the available pool, the instance is not associated with any
particular entity object identity. Any of these pooled instances may be used to
execute finder (ejbFind) or home (ejbHome) methods.

An instance transitions from the pooled state to the ready state when the container
selects that instance to service a client call to an entity object. There are two possible
transitions from the pooled to the ready state: through the creation of an entity
(ejbCreate and ejbPostCreate) or through the activation of an entity (ejbActivate).
When an entity bean instance is in the ready state, the instance is associated with a
specific entity object identity. While the instance is in the ready state, the container
can synchronize the instance with its representation in the underlying data source
whenever it determines the need to using ejbLoad and ejbStore methods. Business
methods can also be invoked zero or more times on an instance. An ejbSelect method
can be called by a business method, ejbLoad or ejbStore method.
The container can choose to passivate an entity bean instance within a transaction. To
passivate an instance, the container first invokes the ejbStore method to allow the
instance to prepare itself for the synchronization of the database state with the
instance?s state, and then the container invokes the ejbPassivate method to return
the instance to the pooled state.
There are three possible transitions from the ready to the pooled state: through the
ejbPassivate method, through the ejbRemove method (when the entity is removed),
and because of a transaction rollback for ejbCreate, ejbPostCreate,or ejbRemove.
The container can remove an instance in the pool by calling the unsetEntityContext()
method on the instance.
What is the difference between ejbCreate() and ejbPostCreate()

Session and Message Driven Bean will have only ejbCreate() method and no
ejbPostCreate() method. Entity bean will have both ejbCreate() and ejbPostCreate()
methods.
The ejbPostCreate method returns void, and it has the same input parameters as the
ejbCreate method. If we want to set a relationship field to initialize the bean instance,
we should do so in the ejbPostCreate method. we cannot set a
relationship field in the ejbCreate method.
The ejbPostCreate() allows the bean to do any post-create processing before it begins
serving client requests. For every ejbCreate() there must be a matching (matching
arguments) ejbPostCreate() method.
What is the difference between find and select methods in EJB

Answers:

A select method is similar to a finder method for Entity Beans, they both use EJB-QL
to define the semantics of the method.
They differ in that an ejbSelect method(s) are not exposed to the client and the
ejbSelect method(s) can return values that are defined as cmp-types or cmr-types.
What is handle in EJB

handle is an abstraction of a network reference to an EJB object. A handle is


intended to be used as a "robust" persistent reference to an EJB object.
When two entity beans are said to be identical?Which method is used to compare
identical or not?

Answers:

Two Entity Beans are said to be Identical,if they have the same home inteface and
their primary keys are the same.To test for this ,you must use the component
inteface's isIdentical() method.

Difference between ejbCrate() ejbpostcreate()

ejbCreate() is called before the state of the bean is written to the persistence storage
(database). After this method is completed, a new record (based on the persistence
fields) is created and written. If the Entity EJB is BMP, then this method must contain the
code for writing the new record to the persistence storage.
If you are developing an EJB following 2.0 specs, you can have overloading methods in
the form of ejbCreateXXX(). This will improve the development so you can have
different behaviour for creating a bean, if the parameters differs. The only requirement is
that for each ejbCreateXXX() you need to have corrisponding createXXX() methods in
the home or local interface.

ejbPostCreate() is called after the bean has been written to the database and the bean
data has been assigned to an EJB object, so when the bean is available.
In an CMP Entity EJB, this method is normally used to manage the beans' container-
managed relationship fields.

"ejbCreate() is called before the state of the bean is written to the


persistence storage (database). After this method is completed, a new
record (based on the persistence fields) is created and written."

Life cycle of entity bean works this way. When the client calls the craete
method on entity home interface, Container calls the ejbCreate() and
ejbPostCreate() method and that time Container associate the bean
instance with Entity Object and moved the bean instance from Pooled
State to Ready State. So That time no record is inserted in the database
Only bean instance is associated with Entity Object. After this Container
calls the ejbStore method to synchronize the bean instance with database
so It writes the bean instance to database. This way the container calls
the method in this sequence

ejbCreate()
ejbPostCreate()
ejbStore()

This is what I am able to figure it out. Please correct me If I am wrong