Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejbFindByPrimary method has a flaw ..... I think

 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all my question is this

Whether it is possible to use a entity bean with out using home.create() method


That is i want my entity bean to load a particular record based on the primary key i am passing. All the examples in the tutorial are given like they are inserting a row into the database by the way of calling home.create which means currently all the instance variables will be allocated then they are calling the Business method.

If you not getting what i am trying to say, follow the coding below

remote=home.ejbFindByPrimaryKey("SB101");

remote.getBalance();

i am assuming that i have a remote and home and i am having accno and balance are instance variables. Then with out calling the home.create() method i want get the balance.


This is not working.

And probably i want to use session bean for this.


Thanks
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you're talking about entity beans (which you seem to be) you don't use create() to get an EjbObject stub unless you're actually inserting a new record in your datastore.

You use a finder or select method, of which findByPrimaryKey(Object pk) is the only required one.

If it's not working you have something wrong in your code. For example you may have a CMP bean where you implemented the finder method, something you should leave to the application server.
Or maybe there is no record with the key you supplied.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic