aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes session bean's ejbRemove() and RemoveException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "session bean Watch "session bean New topic
Author

session bean's ejbRemove() and RemoveException

Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
got a question for you guys:

according to API, SessionBean.ejbRemove() does NOT throw RemoveException.
So, can a client get RemoveException when calling any remove() method on a session bean?

Thanks.

my guess is it will never get RemoveException for session bean.


Kyle Tang<br />SCJP 91<br />SCWCD 96<br />SCBCD 95
Sandesh Tathare
Ranch Hand

Joined: Jun 22, 2003
Posts: 82
Kyle,

my guess is it will never get RemoveException for session bean.


RemoveException for Session Beans is thrown in following cases:

1] Because session objects do not have primary keys that are accessible to clients, invoking the javax.ejb.EJBHome.remove(Object primaryKey) method on a session results in the javax.ejb.RemoveException.
(Refer to section 6.3.2 Removing a session object of EJB 2.0 specification)

2] Because session objects do not have primary keys that are accessible to clients, invoking the javax.ejb.EJBLocalHome.remove(Object primaryKey) method on a session results in the javax.ejb.RemoveException.
(Refer to section 6.4.2 Removing a session object of EJB 2.0 specification)

3] If a session bean instance is participating in a transaction, it is an error for a client to invoke the remove method on the session object´┐Żs home or component interface object. The container must detect such an attempt and throw the javax.ejb.RemoveException to the client.
(Refer to section 7.6.4 Restrictions for transactions of EJB 2.0 specification)

Remember, RemoveException is declared in throws clause of following methods:
EJBHome:
1] remove(Handle handle) and
2] remove(Object primaryKey)

EJBLocalHome:
1] remove(Object primaryKey)

EJBObject:
1] remove()

EJBLocalObject:
1] remove()

Hope this helps.
[ November 17, 2004: Message edited by: Sandesh Tathare ]

Regards,<br />Sandesh<br />(SCJCP, SCWCD, SCBCD - 99%, OCP-1)<br /> <br />Either find a way or create one.
sandeep vaid
Greenhorn

Joined: Jul 08, 2004
Posts: 20
The remove()behaves different for Stateful & Stateless session beans.

In Stateful session beans the client can get the javax.ejb.RemoveException
becuase clinet calls the remove() hence ejbRemove() is called on bean here the EJBObject is directly related to Bean Instance throu out the session of client.

But if the case is Stateless Session Bean then the client is not responsible for calling ejbRemove() of the bean it will be called by container when it wants to do depending on load or other criterias, so the client will never get this type of Exception even if the client call
remove() on stateless session bean.
i.e. Here remove() will never call ejbRemove() on bean instance.

Thanks!!
Sandy
Sandesh Tathare
Ranch Hand

Joined: Jun 22, 2003
Posts: 82
Sandy,

client will never get this type of Exception even if the client call
remove() on stateless session bean.


Client would get RemoveException, if client calls remove(Object PK) on Stateless Session Bean. I have tried this out.
Arun Krishnamoorthy
Greenhorn

Joined: Nov 03, 2004
Posts: 22
I think both of you are right...

Sandy...when remove() is called on the remote interface, ejbRemove() never gets called for a stateless session bean and hence, no RemoveException is thrown.

Sandesh...since stateless session beans do not have a primary key, calling remove (Object PK) would throw a RemoveException.
Kyle Tang
Ranch Hand

Joined: Aug 22, 2002
Posts: 78
Thanks a lot guys. That cleared things out.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: session bean's ejbRemove() and RemoveException