ejb@glassfish.java.net

ejb3 business method with covariant return type

From: Cheng Fang <Cheng.Fang_at_Sun.COM>
Date: Fri, 11 Aug 2006 11:28:45 -0400

When I use such a business method in a simple ejb3 stateless session
bean, it works fine :-)

@Remote
public interface EchoRemote {
    void echo();
    void echo2();
    Object getMessage();
}
------------------
@Stateless
public class EchoBean implements com.foo.ejb.EchoRemote {
   ...

    public String getMessage() { //String, instead of Object, is returned
        return "A message from EchoBean";
    }
}

When I apply a @TransactionAttribute(TransactionAttributeType.MANDATORY)
on this business method, the annotation is ignored.
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public String getMessage() { //String, instead of Object, is returned
        return "A message from EchoBean";
    }

I expect a TransactionRequiredException or the like, since my web client
doesn't start transaction, but no exception occurred. The generated
ejb-jar.xml after deployment contains no transaction attribute for any
methods. So the default REQUIRED is always used.

If I change the return type to Object, I got the expected exception.

I suspect all method-level annotation on such methods are ignored,
though I haven't tested other annotations.

This looks like a bug, unless ejb spec has special restrictions on
covariant return type.

-- 
Cheng