aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB creat method confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB creat method confusion" Watch "EJB creat method confusion" New topic
Author

EJB creat method confusion

A Wolfe
Greenhorn

Joined: Sep 08, 2003
Posts: 23
I'm a little confused about CMP ejb create methods. I've few questions:
1- Assume that you have a CMP ejb named Product. It has four columns. Prod_id (primary key), price, desc, status. You call home.create(String prod_id) method to get hold of the product EJB object. At this point, is the data stored in the database table product? If not, exactly at what point data is stored back in the database?
2- Do you have to specifically call a particular method to store the data back to database? If so, which method do you need to call?
3- Do you need to call ejbCreate method of product ejb object too? My understanding is that all you need to call is home.create(String) method in the above and container takes care of calling the ejbCreate method in the corresponding product object. Am I right?
Thanks.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by A Wolfe:
I'm a little confused about CMP ejb create methods. I've few questions:
1- Assume that you have a CMP ejb named Product. It has four columns. Prod_id (primary key), price, desc, status. You call home.create(String prod_id) method to get hold of the product EJB object. At this point, is the data stored in the database table product? If not, exactly at what point data is stored back in the database?
2- Do you have to specifically call a particular method to store the data back to database? If so, which method do you need to call?
3- Do you need to call ejbCreate method of product ejb object too? My understanding is that all you need to call is home.create(String) method in the above and container takes care of calling the ejbCreate method in the corresponding product object. Am I right?
Thanks.

1. In the moment you call EJB create the container will also create an object in the database for you
2. you don't have to do anything. The data will be stored immediatly. This is quite dangerous which is one reason for the Transfer Object Pattern from Sun
3.you only call create() the ejbCreate() method is only used by the container. You will see that your Home Interface has no ejbCreate method.
You cannot access your EJB's directly, only the Interface.
When you call home.create() the container will call ejbCreate()
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
1- Assume that you have a CMP ejb named Product. It has four columns. Prod_id (primary key), price, desc, status. You call home.create(String prod_id) method to get hold of the product EJB object. At this point, is the data stored in the database table product? If not, exactly at what point data is stored back in the database?
Yes, the data has been inserted into the database at this point.
2- Do you have to specifically call a particular method to store the data back to database? If so, which method do you need to call?
No, the Container implicitly handles storing to the database. The actual behavior is dependent on various cache and transactional settings that you can tweak.
3- Do you need to call ejbCreate method of product ejb object too? My understanding is that all you need to call is home.create(String) method in the above and container takes care of calling the ejbCreate method in the corresponding product object. Am I right?
You are right, there is no need to call ejbCreate(), it is the Container's job to manage the lifecycle of the entity. In fact, the client will never call ejbAnything. The client only interacts thru those methods provided in the home and remote interfaces (or local interfaces).
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Damn! Oliver beat me to the punch. :roll:
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
just a matter of speed Chris
 
 
subject: EJB creat method confusion