Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

remove() method in stateful session bean

 
sangeeta kapoor
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a stateful session bean is passivated and remove() method is called by the client, will it be first activated or straight away destroyed
Thanks
 
ShivPrakash Srivastava
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sangeeta,

You cannot call any method on a passivated bean.Passivated state means the bean is not active and is written to some temporary Storage to conserve resource.

Regards
Shiv
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot call any method on a passivated bean.Passivated state means the bean is not active and is written to some temporary Storage to conserve resource.

This is not correct. The remove() method is treated by the container as a business method, so the container will activate the bean and then invoke ejbRemove() on it.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Roger has written is right but then I think that it depends upon the container implementation. Although I am saying that the container will treat it as a business method but it doesn't make much sense to activate a bean and call remove on it. In case of entity beans it is because of cascade-delete that the container will activate the bean and will remove it.

But in stateful bean deserialize and then call ejbRemove doesn't make much sense as most of the time the code that will be in ejbRemove and ejbPassivate will be same to make sure that the code is always executed.

Sawan
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does not depend upon the container implementation, it is a requirement. Is remove() a container callback? No. Is remove() a business method? Yes. (Ask yourself if remove() begins with "ejb", it does not so it must be a business method as the only rule concerning business method names for entity and session beans is that they must not begin with "ejb".)

Also, it makes perfect sense for a container to always activate a passivated bean in order to invoke ejbRemove() on it. Just think of the confusion if your code in ejbRemove() may or may not be run depending on whether the bean instance happened to be passivated or not.
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Roger has written is right but then I think that it depends upon the container implementation

My point was that it should have been left over to the container provider and in hurry i wrote something else [the above lines in my previous post].


Also, it makes perfect sense for a container to always activate a passivated bean in order to invoke ejbRemove() on it. Just think of the confusion if your code in ejbRemove() may or may not be run depending on whether the bean instance happened to be passivated or not.

There are many cases when the ejbRemove() may not be called like bean times out in passivated state. The above case won't be the only scenario. I was just thinking from the point of view of the performance that it doesn't makes much sense to activate the passivated bean and remove it. Its a performance kill.

Anyways if this is what specs says then there is nothing much to write


sawan
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic