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

Entity beans from the client’s point of view

image with no caption

The client wants to do database stuff, but in a Java OO way.

  • Make a new entity (an SQL INSERT)

  • Delete an entity (an SQL DELETE)

  • Update entity state (an SQL UPDATE)

  • Search/query on entities (an SQL SELECT)

The client interface for an entity bean is a little different from that of a session bean. For example, when a session bean client wants to get a bean, so that it can call the bean’s business methods, the client calls create() and the Container allocates a new EJB object.

But what if a client wants to use an existing entity bean? For example, what if the client doesn’t want just some random entity, but wants the EJB object of a specific entity, say, Bart Simpson # 12? In that case, a create() won’t work. The client doesn’t want a new entity, but wants a reference to an existing entity. So as you’ll see in a minute, the client interface for an entity bean adds (and must have) one or more finder methods.

The next two pages are high-level pictures of how entity beans are created (insert), and found (select). The scenarios in these pictures will be filled in with a lot more detail as we go through this chapter, but for now you can relax.

Entity bean overview

Scenario: client wants a reference to an existing entity

image with no caption
  1. After doing a JNDI lookup on the entity ...

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