Skip to main content

2 ejb with the same local interface

4 replies [Last post]
mitroiasi
Offline
Joined: 2007-08-24
Points: 0

Hi,

I have a problem concerning EJB 3.
I want to create 2 stateless EJB which implement the same local interface. The j2ee container, which I used, is Glassfish version 2.1.
I searched in Internet but none of the found solutions works.

For example I used my EJB in this form:
@EJB(beanName="QuotationBusinessService1") - where beanName is the name of the EJB-bean class.

Is there any solution?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ksak
Offline
Joined: 2005-05-20
Points: 0

This should work. Any number of EJB components can implement the same interface. If the interface is FooLocal, you would have :

@Stateless
public class ABean implements FooLocal { ... }

and

@Stateless
public class BBean implements FooLocal { ... }

ABean's ejb-name is "ABean". BBean's ejb-name is "BBean".

To acquire an EJB reference to a bean that implements FooLocal, in addition to specifying the type as FooLocal, you'll need to disambiguate the ejb-name.

@EJB(beanName="ABean")
public FooLocal fooLocalRef;

or

@EJB(beanName="BBean")
public FooLocal fooLocalRef;

Is this equivalent to what you tried? If so, what exact error did you receive?

Felipe Gaúcho

it works with generics too ??

* I tried with generics and the server claims disambiguation.. if I
can use it with generics, it will remove tons of empty classes from my
project :)

On Wed, Jan 20, 2010 at 4:15 PM, wrote:
> This should work.  Any number of EJB components can implement the same interface.   If the interface is FooLocal, you would have :
>
> @Stateless
> public class ABean implements FooLocal { ... }
>
> and
>
> @Stateless
> public class BBean implements FooLocal { ... }
>
> ABean's ejb-name is "ABean".   BBean's ejb-name is "BBean".
>
> To acquire an EJB reference to a bean that implements FooLocal, in addition to specifying the type as FooLocal, you'll need to disambiguate the ejb-name.
>
> @EJB(beanName="ABean")
> public FooLocal fooLocalRef;
>
> or
>
> @EJB(beanName="BBean")
> public FooLocal fooLocalRef;
>
> Is this equivalent to what you tried?  If so, what exact error did you receive?
> [Message sent by forum member 'ksak' (kenneth.saks@sun.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=381976
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

--
------------------------------------------
Felipe Gaúcho
10+ Java Programmer
CEJUG Senior Advisor

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

ksak
Offline
Joined: 2005-05-20
Points: 0

No, generics aren't covered right now.

Felipe Gaucho

AFAIK no :(

On 20.01.2010, at 10:10, glassfish@javadesktop.org wrote:

> Hi,
>
> I have a problem concerning EJB 3.
> I want to create 2 stateless EJB which implement the same local
> interface. The j2ee container, which I used, is Glassfish version 2.1.
> I searched in Internet but none of the found solutions works.
>
> For example I used my EJB in this form:
> @EJB(beanName="QuotationBusinessService1") - where beanName is the
> name of the EJB-bean class.
>
> Is there any solution?
> [Message sent by forum member 'mitroiasi' (mitroiasi@yahoo.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=381913
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net