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
Favourite topic WSAD entity bean example 🙂 without writing a single line of code get the entity bean in place here we go
- Create new project EntityBean
- Create new Enterprise bean
- Select Type Entity bean
- Select CMP bean 2.0
- Bean detail select Remote & Local both the interfaces
- Select the project
- Run the Entity bean on server
- Configure new Test Server or run on existing server
- Create table and deploy entity bean
- It will show success message, i.e. it will test the create and alter statement on newly created table.
- Select server client local
- It will open Test Client
- Click on EntityExampleLocal
- Click on CMPLocal.findByPrimaryKey
- 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.
-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.