Hold On! The EJBs will CALL BACK…..

EJB 2.0 introduced the bean model in which the programmer writes the code for the entity bean in a super class devoid of any jdbc. The container subclasses this bean and generates the jdbc itself. Thus there is a clear separation between the business logic and the jdbc.The actual bean is a combination of this subclass and super class. EJB 1.1 does not require such subclassing. EJB 2.0 on the other hand must support both these models.
In EJB 2.0 the superclass does not have any declared fields. On the other hand the persistent fields are container generated in the subclass. The subclass not the super class implements the get/set methods. The super class on the other hand contains empty abstract method declarations and the super class itself is declared abstract.
Any method in the super class that needs to use instance variables for some operation has to call these abstract get/set methods instead. The ejbCreate method in the entity bean (super class) sets the value of the primary keys by calling the corresponding set methods instead of initializing the instance variables unlike EJB 1.1. The container knows which fields are container managed from the information in the deployment descriptor ejb-jar.xml. Finder methods are container generated from the information in the deployment descriptor.
Guidelines for container managed persistent entries
These methods are left empty for CMP beans.
call the beans abstract set methods to initialize the primary keys.
you can pass your beans ejb object reference to other beans.
Acquire any required resources such as socket connections etc.
Release any acquired system resources such as socket connections, etc.
Called after the data is loaded into the bean
You can work on the data loaded by the container from the db such as decompressing etc.
Called just before data is stored to the database.
You can work on data about to be put into the db such as compressing etc.
Called before the bean and the corresponding data in the bean is destroyed.

The only differences between ejb 1.1 and ejb 2.0 implementations come in the bean class. The remote, home and primary key classes remain unchanged.

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: