Justin Wong
Justin Wong

Reputation: 1497

Instantiating directly vs JNDI lookup

I've implemented EJB 2.0 session beans as POJOs behind an EJB facade.

I wish to get a reference to Bean B from Bean A. Should I:

a. Use ejb-ref and perform a JNDI lookup

b. Instantiate an instance of B directly(since it's a POJO)

Both would give me the same result. What are the pros and cons of each method? Why should I choose one over the other?

Thanks.

Upvotes: 0

Views: 470

Answers (1)

Met
Met

Reputation: 3172

You never instantiate managed objects yourself. You should perform a lookup. EJB 2.0 are far from POJOs. EJB 3.x are POJOs but again you would never instantiate them yourself because of many reasons.

Upvotes: 1

Related Questions