File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Queries on Entity Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Queries on Entity Beans" Watch "Queries on Entity Beans" New topic

Queries on Entity Beans

Saurabh Chaubey
Ranch Hand

Joined: Oct 16, 2005
Posts: 101
I have the following questions regarding Entity beans:-

1. Why the ejbCreate() method in an entity bean always return null? Is this behaviour ejbCreate() method same for both CMP and BMP Entity beans?

2. If ejbActivate() and ejbPassivate() methods in an entity bean can get a reference of their EJBObject, then why these methods cannot access the security information about the client?

Thanks in advance!
Napu Sun
Ranch Hand

Joined: Apr 18, 2006
Posts: 33
I only can help for the second question,
in ejb specification Page 436(21.2.5) and 451(21.6.5)
It is mentioned that container's responsibility is providing security context in business methods.

for the first question, I am also looking for it.
Kevin DesLauriers
Ranch Hand

Joined: Nov 28, 2005
Posts: 43
Somewhere between ejbActivate and ejbLoad the container associates the bean with a client. The same thing occurs after ejbStore() and before ejbPAssivate(). The entity bean is too general during activate and passivate to know about the client that is calling the business method. It has not been associated with a client or transaction.

I hope this helps.
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
I can explain you for the first question,

According to the specification the primary key for the entity must be set before ejbCreate completes, Once that is done the primary key is available through getPrimaryKey method of EntityContext. There should be some way to communicate to the container what primary will be used for this entity. In case of CMP we have to do something like setId() (id is the primary key and a virtual persistence field). So when ejbCreate returns the container knows the primary key and we return null, In case of BMP there is no way the container knows what the primary key is and hence we need to return the primary key class and not null from the ejbCreate of BMP bean.
Saurabh Chaubey
Ranch Hand

Joined: Oct 16, 2005
Posts: 101
Thanks Amol for the explanation!!!
I agree. Here's the link:
subject: Queries on Entity Beans
jQuery in Action, 3rd edition