ejb@glassfish.java.net

Re: ejb3 business method with covariant return type

From: Cheng Fang <Cheng.Fang_at_Sun.COM>
Date: Tue, 15 Aug 2006 10:18:13 -0400

Linda,

Thanks for the clarification.

Cheng


Linda DeMichiel wrote:

>
>
> Kenneth Saks wrote:
>
>> Cheng Fang wrote:
>>
>>> 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";
>>> }
>>> }
>>
>>
>>
>> This isn't allowed for Home/LocalHome create() methods but I'm not sure
>> whether the spec allows it for business methods. Linda?
>>
>
> The EJB 3.0 business interface is just a plain Java interface, which the
> bean class itself can implement. There aren't any restrictions here
> against use of covariant return types.
>
> Note though that the old rules still apply to the EJBObject and
> EJBLocalObject interfaces (as well as the Home/LocalHome interfaces).
> For those, the return types must match.
>
>>>
>>>
>>> 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.
>>>
>>
>
> Looks like a bug.
>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>