basic question on EJB 2.0
Hi
I am new to EJB's
Can the business methods in EJB 2.0 throw java.rmi.RemoteException.
When I try to import some sample code from one of our systems to WSAD it gave me a warning saying that this methods should not throw RemoteException.
But When I looked into the "Mastering EJB 2.0 " book from EdRoman, all the examples shows throwing RemoteException for the methods
Please advise
Thanks in advance
[446 byte] By [
newSuna] at [2007-9-29 13:27:31]

If your business method is inside the Remote Interface
it has to throw a RemoteException (think at a Session Bean
called remotely from a Client).
If your business method is inside a Local Interface
it doesn't throw the RemoteException (think at
an Entity Bean called by a co-located Session Bean).
I think this is the real difference
(but I'm not sure at 100 % :-))
Hi
Moreno
Moreno
Thanks for the answer.
The IDE is giving a warning every instance where a RemoteException is thrown.
Moreover when I look into the EJB spec , I saw the following line
Topic 18.6
"EJB 1.0 specified that the enterprise bean business methods and container-invoked callbacks
use the java.rmi.RemoteException to report non-application exceptions. This practice
was deprecated in EJB 1.1齮he enterprise bean methods should use the
javax.ejb.EJBException or other suitable RuntimeException to report non-application
exceptions.""
Please comment
Any one , EJB experts pls comment
Hello Friend ,
Since you are using websphere application developer , it does not
require as it has implicit declarations , but if you using some other
editor like editplus , definitely you need to throw exceptions as said
by EDRomon.
Hope it clarifies ..
Bye..
Mahesh L
==========
Hello Friend ,
Since you are using websphere studio application developer , it does not
require as it has implicit declarations , but if you using some other
editor like editplus , definitely you need to throw exceptions as said
by EDRomon.
Hope it clarifies ..
Bye..
Mahesh L
==========
Mahesh
Thanks for the response
Forget about WSAD ,
The following statement is from the EJB specification from sun, this is from the latest EJB spec.
Topic 18.6
"EJB 1.0 specified that the enterprise bean business methods and container-invoked callbacks
use the java.rmi.RemoteException to report non-application exceptions. This practice
was deprecated in EJB 1.1齮he enterprise bean methods should use the
javax.ejb.EJBException or other suitable RuntimeException to report non-application
exceptions.""
Can anyone help me with this?I like to know why is it different , or what am i missing here?
Hi,
EJB Specs
=========
Compatibility Note: EJB 1.0 allowed the ejbCreate method to throw the java.rmi.RemoteException to indicate a non-application exception. This practice was deprecated in EJB 1.1齛n EJB 1.1 or EJB 2.0 or later compliant enterprise bean should throw the javax.ejb.EJBException or another RuntimeException to indicate non-application exceptions to the Container (see Section 18.2.2). An EJB 2.0 or later compliant enterprise bean should not throw the java.rmi.RemoteException from the ejbCreate method .
Rgds,
Seetesh
Seetesh
Thanks for the answer.
I don't think it is just the ejbCreate method . See this lines from the latest EJB spec from sun. It talks about business methods also.
18.3.11 Support for Deprecated Use of java.rmi.RemoteException
The EJB 1.0 specification allowed the business methods, ejbCreate, ejbPostCreate,
ejbFind<METHOD>, ejbRemove, and the container-invoked callbacks (i.e., the methods defined in
the EntityBean, SessionBean, and SessionSynchronization interfaces) implemented in
the enterprise bean class to use the java.rmi.RemoteException to report non-application exceptions
to the container.
This use of the java.rmi.RemoteException was deprecated in EJB 1.1齟nterprise beans written
for the EJB 1.1 specification should use the javax.ejb.EJBException instead, and enterprise
beans written for the EJB 2.0 or later specification must use the javax.ejb.EJBException
instead.
Exception Handling Enterprise JavaBeans 2.1, Proposed Final Draft 2 Client齭 View of Exceptions
Sun Microsystems, Inc.
The EJB 1.1 and EJB 2.0 or later specifications require that a container support the deprecated use of the
java.rmi.RemoteException. The container should treat the java.rmi.RemoteException
thrown by an enterprise bean method in the same way as it is specified for the javax.ejb.EJBException.
Note: The use of the java.rmi.RemoteException is deprecated only in the above-mentioned
methods. The methods of the remote and remote home interface still must use the java.rmi.RemoteException
as required by the EJB specification.
Hi newsun,
I am still searching for the term "Report non-application exceptions
to the container". That is what is important for throwing a RemoteException. No where they have mentioned the reasons for the same.
Brief u later when I find answers to these.
Hope someone from Sun lightens this topic.
Rgds,
Seetesh
Seeteesh Thanks for the input , Let me know if u find somethingThanks again
The only reference to this non-application exception is
http://java.sun.com/j2ee/1.4/docs/relnotes/releasenotes.html
No : 4860807
Description :
Container fails to throw TransactionRolledbackException in caller's tx context.
A container-managed transaction enterprise bean is invoked with an active client transaction. The invoked bean throws a non-application exception, or an error is thrown from a method that runs in the context of the caller's transaction context.
In this situation, the container is expected to throw a javax.transaction.TransactionRolledbackException to a remote client. Instead, the container throws a RemoteException.
Solution : None.
Dont think this could be the problem but still searching for more info.
Rgds,
Seetesh
Ifyour bean is a local bean then yes it doesn't throw RemoteExceptionIstiaque. http://www.ideas2work.com
Istiaque.Thanks for the input If i am right local beans concept came in EJB 2.0. If I look back to my post , the EJB spec says throwing remote exception was deprecated in 1.1 itself.
The EJB 1.1 specification deprecated the use of throwing RemoteException on the methods of a bean class to indicate non-application exceptions, in other words, an exception that has nothing to do with the application code, but rather with the container and/or J2EE server configuration or runtime. This is not only for container methods (ejbCreate(), etc...) but also for the business methods (or application methods) defined within the bean class.
However, even though the RemoteException should not be included in the bean class, it MUST still be included with the business methods defined in the Remote Interface. This is because the container may need to throw this exception back to the client during invocation of the business method. So, even though you have a business method defined in the bean class as:
public void foo() {
...
}
The same method in the remote interface needs to be declared as:
public void foo() throws RemoteException;
If you received some third-party code that includes the RemoteException in the throws clause of a bean's business method, then it is simply not EJB 1.1 compliant and you will get the warning within a WSAD EJB project. By removing the RemoteException from the bean class (and keeping it in the Remote Interface), it should eliminate these warnings.
Good Luck.
atdemmin Thanks for the answer , that clears it.