• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

CMP & BMP : When is data actually inserted on the DB ?

 
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm studying for SCEA exam. Reading EJB books raised one
question. In which call-back method data is actually
inserted on DB ?
I believed that the right answer was during "ejbPostCreate",
so I have built a simple use case with WLS samples.

But it's not accurate. Data is actually inserted in "ejbStore"
which is called AFTER ejbPostCreate.
And it's the same both for CMP and for BMP.

Can anybody confirm this ? I have seen whiz lab exam has separate question for both CMP and BMP.....

Thanks in advance
Francesco
 
Francesco Marchioni
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi again, still me!
I have just found the whiz lab question

"During the creation of a BMP Entity bean when is data actually inserted on DB" ?

Answer: During the execution of ejbCreate()

But it's not true!!!
you can verify by yourself....

please provide your feedback..........
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Francesco Marchioni:
In which call-back method data is actually inserted on DB?



BMP - ejbCreate. See Figure 26 OID of Creation of an entity object with bean-managed persistence on page 136 in the EJB 1.1 specification.

ejbStore() is called to update the data of a BMP bean. See Figure 28 OID of passivation and reactivation of an entity bean instance with bean-managed persistence on page 138.


CMP - None. The container is responsible for the insertion of the data - so it can't happen during any callback method. See Figure 27 OID of creation of an entity object with container-managed persistence on page 137 in the EJB 1.1 specificatioin. The insertion occurs after ejbCreate and before ejbPostCreate.

ejbStore() is called before the container updates the data for a CMP bean after which ejbPassivate() can be called. See Figure 29 OID of passivation and reactivation of an entity bean instance with CMP on page 139.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Francesco, why do you think ejbCreate() does not insert data? Is it because you set break point somewhere in ejb[Post]Createm watch database content with DB client and cannot see new data there? If so, keep in mind that EJB container probably would conduct severall method calls in a single tracsaction and commit it only when whole creation process successful. Otherwise transaction will be rolled back. Anyway, the "I" of ACID makes new data invisible until transaction commits.

As ejbPostCreate() called, data already exists in database, otherwise you wouldn't have been able to set CMR fields.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pavel Grushetzky:
Francesco, why do you think ejbCreate() does not insert data?


Part of the problem is identifying whether you are talking about a Bean Managed Perstence (BMP) Entity Bean or a Container Managed Persistence (CMP) Entity Bean. This is exasperated by the fact that SCBCD study guides only discuss CMP entity beans (because that what the SCBCD exam covers). Compounding the problem is the fact that entity beans can only use Container Managed Transactions (CMT) which sometimes confuses people into thinking that Entity Beans can only be CMP.

Bottomline:
In a BMP Entity Bean the bean provider is responsible for inserting the DB record in the ejbCreate.
In a CMP Entity Bean the bean provider is responsible for setting the bean fields that compose the primary key (and presumably any other "not-null" constrained fields) in the ejbCreate - so that after the ejbCreate the container can use the values in those fields to issue the necessary "insert" statement.
 
please buy my thing and then I'll have more money:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic