I've been reading ejb tutorials. From what I understand, there are 3 kinds of ejbs : entity beans, session beans and message driven beans. Entity beans can be BMP or CMP. My question is can session beans be BMP or CMP too? Or are they CMP only?
Entity Beans can be Container managed persistence (CMP) or Bean Managed. Most of the app servers these days complaint EJB 2.0 mean they have a well-written Persistence mechanism, where how the data is persisted is hidden from the bean user. Bean user can totally dedicate the time for business process.
We dont save a Session Bean, but we do save Entity Beans. Because they are suppose to be Data Entities. Like Customer, Order, Student etc.
Persistence is an Enity beans behaviour and not with Session beans. We dont save Session beans, So the answer to your question is NO. Session beans are neither BMP's nor CMP's. They are there to help you to to write your business methods in a distributed environment.
Normally, In a scenario where you want to validate and store a flight booking. Then a session Bean (stateless) will do the validation part and then call the entity bean to create a record to fulfil the request.
hope this helps.
I've been reading ejb tutorials. From what I understand, there are 3 kinds of ejbs : entity beans, session beans and message driven beans. Entity beans can be BMP or CMP. My question is can session beans be BMP or CMP too? Or are they CMP only?BMP
- Bean managed persistence
- Developer has to write persistence code for ejbLoad(),ejbStore() for entity beans
- Should follow this approach only when its bare necessity to write your own persistence logic.Usually container managed persistence is quite sufficient and less error prone.
- Container managed persistence
- Developer maps the bean fields with the database fields in the deployment descriptors.
- Developer need not provide persistence logic (JDBC) within the bean class.
- Containiner manages the bean field to DB field synchronization.
The point is only ENTITY beans can have theier pesristence mechanism as CMP or BMP. Session beans, which usually contains workflow or business logic should never have persistence code.Incase you choose to write persistence within your session bean, its usefull to note that the persistence is managed by the container BMP.Session beans cannot be CMP and its not possibel to provide field mapping for session bean.