Consider the following stateful EJB (3.x):
First remote interface:
@Remote
public interface Interface1
{
public void setValue(int v);
}
Second remote interface:
@Remote
public interface Interface2
{
public int getValue();
}
Implementation of the interfaces:
@Stateful
public class TheEJB implements Interface1, Interface2
{
int value = 0;
public void setValue(int v) {value = v;}
public int getValue() {return value;}
}
If I do the following in my client:
Interface1 interface1 = (Interface1)initialContext.lookup("***JNDI for Interface1***");
Interface2 interface2 = (Interface2)initialContext.lookup("***JNDI for Interface2***");
interface1.setValue(1);
System.out.println(interface2.getValue());
The output to the console will be 0 because interface2 does not point to the same instance of the session bean as interface1.
So, my question is if it is possible, upon creation of interface2 to get it to point to the same instance of the bean as interface1 (and thus get the output 1)?
I do realise this can be achieved by putting both methods in the one interface but let's say that I want to two use two interfaces for one reason or another.
Many Thanks.