EJB cont


Entity Bean

An entity bean is representation of single row in a databases. Entity always be an heavy component. But the connectivity to database will be a transparent to developer. When you create a new entity bean automatically in database new row will be added.

ORM – Object Relational Mapping, row in a table will be one object in memory.

Stateless Session Bean can have pooled creation.

Statefull Session Bean can have cached creation.

But Entity bean can have either cache or pooled creation.

Whenever you need to work with processed or in other words process matters over data you should use session bean. But whenever you want to work with DATA or in other words DATA matters over process you should use entity beans.

Entity beans are heavy object because its a in memory object for database table. Where each instance of entity bean object refer to one record set in table or row in table.

Entity beans are of two types
Bean Managed Persistence
Container Managed Persistence

CMP Bean
Local Client
Remote Client

Favourite topic WSAD entity bean example 🙂 without writing a single line of code get the entity bean in place here we go

  1. Create new project EntityBean
  2. Create new Enterprise bean
  3. Select Type Entity bean
  4. Select CMP bean 2.0
  5. Bean detail select Remote & Local both the interfaces
  6. Select the project
  7. Run the Entity bean on server
  8. Configure new Test Server or run on existing server
  9. Create table and deploy entity bean
  10. Finish
  11. It will show success message, i.e. it will test the create and alter statement on newly created table.
  12. Select server client local
  13. Finish
  14. It will open Test Client
  15. Click on EntityExampleLocal
  16. Click on CMPLocal.findByPrimaryKey
  17. Enter value into and click invoke.

This how you will be testing tyour entity beans. Just now what we have seen is the Top to Bottom appoch, we have another approach which is Bottom to Top where in we will be having table already existing in and then will be creating the entity bean accordingly.  

Facts……….

-EJB can be accessed using servlet
-Entity Bean should not be remote
-Session Bean should not be local
-In entity bean you should not use primitive data-type.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s