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

Entity Bean remove()

 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I was going through head first EJB chapter on entity beans and the authors say that once a client calls bean's remove() method, the ejbObject references held by this client as well as all other clients become invalid. [Ch5, Pg 282]

My question : How will other clients know that ejbObject reference they hold has become invalid. Do they have to catch some exception?

Related question : In stateful session beans there is a session timeout associated. After that the ejbObject reference becomes invalid. Is there a similar timeout associated with entity beans. If not, then how the client is supposed to know that its ejbObject reference has become invalid.

Trivial Question : I called home.findByPrimary key method. I am about to call a business mehtod on my ejbObject reference. But someone deleted the entity from database before I could do that. So in my business method invocation I will get some exception. How am I going to deal with this situation? Should I implicitly assume that data is deleted?

Thanks!
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohan,


My question : How will other clients know that ejbObject reference they hold has become invalid. Do they have to catch some exception?

Usually clients don�t access the bean objects directly; they have remote or local interfaces for that. Hence I believe that they won�t know when the reference becomes invalid, unless they either run a business method, deserialize the bean handle, etc. Either way the container will throw an exception that should be properly handled by the application.

Related question : In stateful session beans there is a session timeout associated. After that the ejbObject reference becomes invalid. Is there a similar timeout associated with entity beans. If not, then how the client is supposed to know that its ejbObject reference has become invalid.

No. Moreover entity ejbs and SFSBs are different type of animals and they don�t have much in common. Usually entity ejbs suppose to be accessed through a finder and they are always supposed to hold the latest data (following the basic load-and-store cycle calling ejbLoad/ejbStore for each transaction). Hence other clients won�t get affected if a bean data was removed even by external processes. The only scenarios when things could go wrong are:
  • Two transactions run at the same time and one updates/reads data while the other remove the data; and this could be avoided through properly setting transaction isolation levels.
  • A client holds a reference/handle to a bean obtained within a previous transaction. This could actually be prevented through good application design.



  • Trivial Question : I called home.findByPrimary key method. I am about to call a business mehtod on my ejbObject reference. But someone deleted the entity from database before I could do that. So in my business method invocation I will get some exception. How am I going to deal with this situation? Should I implicitly assume that data is deleted?

    Again you won�t interact directly with the bean object though and again you�ll mostly access the bean and the underlying data within a transaction context. You can deal with this type of problems fairly easy, by setting the proper transaction isolation level.
    Regards.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic