permaculture playing cards
The moose likes EJB and other Java EE Technologies and the fly likes cmp vs bmp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "cmp vs bmp" Watch "cmp vs bmp" New topic

cmp vs bmp

vara prasad
Ranch Hand

Joined: Dec 21, 2004
Posts: 47
1)please tell me what is the
difference between cmp and bmp
clearly. i read to many books so that i m now in confused
where exatly we can differ cmp and bmp.
if you can tell me but not give me other sources t o read
if i read those things i will confused more. so please
clearly give the differenses

2)if we put jdbc code in bmp`s pasivating method what will hapen?

thank you
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

CMP is container managed persistence. This means the the EJB container handles all the database stuff for you. BMP is bean managed persistence where you have to write the code yourself.

CMP is much more common than BMP. If you have to write the code yourself, you often are better off using an object/relational mapping framework or even pure JDBC.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Vara,

2)if we put jdbc code in bmp`s pasivating method what will hapen?

Right from the top you must notice that the container saves the bean�s state into the database before passivation, calling the ejbStore(). Hence there is no reason for you to provide any database code in ejbPassivate(). However by doing so, your jdbc code will execute in a very unpredictable manner, because you have no way to control the way your container passivates/activates the bean. Hence from a design standpoint you cannot implement any business logic inside of ejbPassivate(), because you�ll never know when this logic will execute, if it will execute at all (although almost certainly ejbPassivate/ejbActivate will be called at least once in a bean life cycle).
Bottom line is that if you ever considered implementing jdbc logic inside of ejbPassivate I can recommend you only one thing: please stay away.

I think, therefore I exist -- Rene Descartes
I agree. Here's the link:
subject: cmp vs bmp
It's not a secret anymore!