Skip to main content

Injecting session EJB to another EJB (both impl. remote and local

1 reply [Last post]
imperfect
Offline
Joined: 2006-10-18

Hi,

i have problem in injecting one stateless EJB (say,
Test1EJB) to another stateles EJB (Test2EJB).

the 2 EJBs both implements local and remote interfaces.

sample code:
-----------------------------------------------------------------
@Remote
public interface Test1EJB
{
public String sayHello();
}

@Local
public interface Test1EJBLocal
{
public String sayHello();
}

@Stateless(name="Test1EJB")
public Test1EJBBean implements Test1EJB, Test1EJBLocal
{

public String sayHello()
{
return "Hello 1";
}

}

=============================

@Remote
public interface Test2EJB
{
public String sayHello();
}

@Local
public interface Test2EJBLocal
{
public String sayHello();
}

@Stateless(name="Test2EJB")
public Test2EJBBean implements Test2EJB, Test2EJBLocal
{
//>>>>>> inject EJB here
//>>>>>>
@EJB
Test1EJB test1;

public String sayHello()
{
return "Hello 1";
}

}

====================================================

but when i deploy the EJBs, error occur saying invalid
EJB reference...

if i do ONLY implement ONE interface
(either Test2EJBLocal or Test2EJB), the error do not
appear....

is it that an EJB, that ACCEPT injection, cannot implement
both remote and local interfaces
(or can only implements one and only one interfaces?)

thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30

> is it that an EJB, that ACCEPT injection, cannot
> implement
> both remote and local interfaces
> (or can only implements one and only one
> interfaces?)

No, there is no such restriction. For reason, which I think is a [b]bug[/b] in the implementation, it is not able to resolve the EJB reference to an actual EJB because the EJB has more than one business interface. Please file a bug.

You can also try using the [b]beanName[/b] attribute as follows
[code]@EJB(beanName="Test1EJB") ...[/code]

Also have a look at the EJB FAQ at https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html
-- Sahoo