• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

EJB creat method confusion

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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()
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damn! Oliver beat me to the punch. :roll:
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a matter of speed Chris
 
Police line, do not cross. Well, this tiny ad can go through:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic