• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bean Managed Persistence

 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I decided to try out BMP in my project, but every book I read said that Container Managed Persistance is(Or eventually become) a much better option. I want to know under What Circumstances is it better to use BMP.
Also I am not clear about why we should access all our entity beans from Session beans, and not directly through JSPs?Kindly throw some light.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several questions here. As for BMP vs CMP, they each have their uses. If your entity beans map fairly easily to relational database tables, then CMP is a big win, it's considerably simpler to program, and you don't have to worry about SQL or database peculiarities. As your objects and their relationships become more complex, there comes a point where CMP may not be good enough or efficient enough. The suggestion is probably to try CMP first, and only consider moving to BMP if you hit data integrity or performance problems.
As for entity beans and session beans, the main thing to bear in mind is that each active entity bean is able to access the database at any point. If your front end system accesses or changes a lot of entity beans at once it can incur a lot of open database connections as each entity bean is stored/retrieved. In many cases it is much easier to manage this as a single load from the entity beans to a session bean, lots of accesses to the session bean, then a save back to the appropriate entities in a more controlled manner.
As well as efficiency and resource-usage effects like the above, using session beans as intermediaries can help development and maintenance of EJB systems. Developing simple dummy session beans early in the process can allow front-end development to progress without having to wait for complex entity beans or BMP code to be bought/produced/customized/integrated. Similarly, the presence of session beans can help to isolate front-end code from the details of the Entities, and vice versa.
 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank for your interesting answer. It has many new ideas that i was unaware of.
One more thing about using session bean to access entity bean : Presently I am not using this approach, because I was told that it is useful to manage session ( when we are using session beans to manage user sessions).
In case we are managing session using JSP etc. then we can directly access the Entity beans from JSPs.
Is this a valid Logic.Ofcourse this logic doesnot consider Performance Issues pointed out by you.So what you have suggested is that if we are managing a stateful session bean and updating its variables from time to time, and only when we finally need to save the data to the database that we use entity bean from the Session bean.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do have access to Entity beans from JSPs, Servlets, and any other Java code you may care to write. It's just that the weight of experience seems to come down in favour of using an intermediary. This intermediary could be any long-lived object with your own customized API and management, but it's one of the jobs Session beans were designed for, and many designers and developers use them that way.
 
mohit joshi
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frank, i appreciate your reply.
"to try CMP first, and only consider moving to BMP if you hit data integrity or performance problems."
Considering that for CMP Entity beans can map to only a single table, what kind of data integrity issues are we refering to,
is it, for instance, that the Entities of Master table cannot be deleted If there are some child records for that master?
I would appreciate if some one has implemented BMP can explain some real life scenario.
[This message has been edited by mohit joshi (edited October 14, 2000).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!