How to call an EJB 2 from an EJB 3 ?

JBoss recipe of the day

The EJB 3 specification mandates that all container should support EJB 2 as well. It’s even possible to inject an EJB 2 into an EJB 3. Here’s how to do it:

@Stateless

public InsertOrderBean implements InsertOrder {
..
@EJB
public BankAccountHome bankAccountHome;
..
void payorder(){
...
BankAccount bankAccount
=  bankAccountHome.create();

bankAccount.debitSum(money);
}

}

Here the BankAccountHome in injected into the EJB InsertOrderBean and, inside method payorder(), used to take one instance of the BankAccount Bean from the pool