It's not a secret anymore!
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Entity Bean ejbCreate method 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 "Entity Bean ejbCreate method" Watch "Entity Bean ejbCreate method" New topic

Entity Bean ejbCreate method

Loka Nalla

Joined: Apr 20, 2006
Posts: 12
Hi all,

I am bit confusion on entity bean creation. Is my understanding below correct?

1) ejbLoad/ejbStore is called by container only when the client calls component business methods.

2) when create is called by client, the container will not call ejbStore but rather it directly inserts record into the database.

Thank you
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Yes, you are correct.

1. ejbLoad/ejbStore called by container before and after executing buisness methods or you can say, before and after bean data gets updated.

2. ejbCreate will be called by container on calling create(..) in home interface. And calling ejbLoad() doesn't make sense in this case, because there is no data yet to refresh bean state. Also calling ejbStore(0 is not required because, client calls create(..) method in home to create a new record and not for updating the existing record.

After ejbCreate() method completes, container call ejbPostCreate() to finish your intialize process like, updating dependent beans.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182

1) ejbLoad/ejbStore is called by container only when the client calls component business methods.

This is one scenario when ejbLoad/ejb?Store is called by container.The container may call these methods n number of times as and when it wants to synchronize the bean data with the data of the entity.
So this is not the onlytime they are called
[ November 18, 2006: Message edited by: Rajan Murugan ]

With Regards,<br /> Rajan<br />"Java Rocks"
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

I would add something in here.

The container will call ejbStore before calling ejbPassivate, and on a server that does active passivation, ejbPassivate is called immediately after ejbPostCreate.

I put together a neat multimedia tutorial the creates a BMP, and just codes a System.out.println("Im in ejbXYZ method"); for each of the methods of the BMP. I then load the BMP on the server, and do thing like create it and call business methods. As this happens, you see exactly what methods are called when.

If you have any doubts about when a certain ejb method is called, you should check it out. People are always blown away when the EJB invokes an ejbLoad and an ejbStore for a simple getter method.

How EJB Lifecycle Methods REALLY work.


-Cameron McKenzie
I agree. Here's the link:
subject: Entity Bean ejbCreate method
It's not a secret anymore!