• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Entity Bean Question  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am new to EJB and after writing few example programs I have a doubt. For example in a CMP bean we always call create() and at the end call remove() in the client. Which means the database will have the orginal empty state, because it was empty at the begining. So for a bank the CMP bean creates account and at the end of session it calls the remove. So there will be no account in the bank. How does Entity bean work for a bank. So I am bit confused, shouldnt we call remove() always.
Thank you
joseph
 
Ranch Hand
Posts: 1934
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove() in case of EJB actually works on the data source and removes the data entry. That is why we call remove() only when we want to remove the data for sure.
 
Joseph Mathew
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Kishore,
I understand that we call remove to remove the entry from the datasource. But say for example the database is empty and we have AccountBean which is a CMP bean. Then on the client side we call create() which creates the account. But at the end of the user session we call remove(), which remove the entry from the database. So now the database is empty as in the begining.
So please suggest a way by which AccountBean can add account details to the database. And the account details should be persistence in the database.
Thank you
Joseph
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Joseph,

But at the end of the user session we call remove(),

I am not able to understand the reason behind the above statement. You seem to understand that we call remove() on Entity bean ONLY WHEN we want to delete the corresponding row in the database BUT from the above statement it seems you feel that "you have to call remove() at the end of session". Why so? Those two views are conflicting.
Are you sure that you are not talking about AccountSession bean which uses AccountEntity bean and you are calling AccountSession.remove()?
Regards
Maulin
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually we call remove() method for Session beans and MDBs, after we are finished using the beans in our client methods. But we do not call remove() method for entity beans, unless our intention is to delete the data from the tables in the database as part of our business logic.
Remember entity beans are used for persistence:
- create() methods are used to insert data into the database.
- remove() methods to delete the data from the database.
- accessor()/mutator() methods to modify the data.
- finder() methods to retrieve the row data.
In your application, you do not need to call the remove() method, if you are only interested in the insertion of rows in the tables and not the deletion of the rows. Anyway, as Maulin suggested it is a good idea to check the type of beans that you are using or intending to use.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I understand that we call remove to remove the entry from the datasource. But say for example the database is empty and we have AccountBean which is a CMP bean. Then on the client side we call create() which creates the account. But at the end of the user session we call remove(), which remove the entry from the database. So now the database is empty as in the begining.
So please suggest a way by which AccountBean can add account details to the database. And the account details should be persistence in the database.


The client only has to keep calling create() on the home interface to insert records into the DB.
The client should certainly call the remove() method to destroy a stateful session bean at the end of a session. It looks to me as if you are calling the wrong remove() method. You must be calling the remove (java.lang.Object primaryKey) method on the home interface for the entity already inserted into the DB; instead, you must call the remove(Handle handle) method on the home interface or the remove() method of the component interface to kill the stateful bean.
Of course, it would be pointless to call remove() for a stateless session bean.
 
Joseph Mathew
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

Thank you very much for your replies. Now I am clear about the remove() method in an EntityBean. I assumed after reading some materials we have to call remove() at the end of a session just like Session Bean. Not its clear.
Again thank you.
joseph
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!