But first, we have to get a home interface reference
In other words, we have to get the stub to the home object... the thing we use to call create(), so that we can get what we really want—the EJB object stub!
When you (the client) want a reference to a home interface, you go through JNDI. The process is pretty straightforward: you give JNDI a logical name (the name the deployer told the server to use), and you get back something that implements the home interface.
What’s JNDI?
JNDI stands for Java Naming and Directory Interface, and it’s an API for accessing naming and directory services. Although JNDI is quite powerful, there are only a few pieces of it you need to know for EJB—how clients find it, how clients use it, how beans use it, and how to put things into it.
The JNDI API can work with many different services, as long as that service has a JNDI driver (called a Service Provider). It’s a lot like JDBC, where you (the developer) use the JDBC API to send SQL statements to a variety of different databases. The JNDI driver translates the method calls you make on the JNDI API into something the underlying naming/directory service understands.
Getting the home interface stub
Get an InitialContext
Context ic = new InitialContext();
The InitialContext (a subtype of Context) is your entry point ...
Get Head First EJB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.