O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

image with no caption

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.

image with no caption

Getting the home interface stub

  1. Get an InitialContext

    Context ic = new InitialContext();

    The InitialContext (a subtype of Context) is your entry point ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required