EJB - Home/Remote and LocalHome/Local interfaces

后端 未结 2 1335
北荒
北荒 2020-12-14 19:45

Revising some past exam papers for an exam mainly focus on component-oriented design and J2EE, I have come across the following question:

A preliminary investiga

相关标签:
2条回答
  • 2020-12-14 20:25

    As pointed out by Yishay, Home/Remote and LocalHome/Local are tied together and the Home interface functions as a constructor.

    Local beans are tied to the JVM they live in, you can not access them from the outside. Remote beans can be accessed from other JVMs.

    I use a similar approach: I always deploy ears. Beans for the ear I make local beans, Beans meant for use by other ears I make remote. But it is possible to use the local beans in other ears, as long as the are deployed in the same JVM

    0 讨论(0)
  • 2020-12-14 20:41

    Home is responsible for the creation of the Remote (kind of like its constructor) and LocalHome and Local have the same relationship.

    In each case the container is giving you a proxy that references the real EJB class that you write.

    If I had to guess, what the question was looking for was the use of remote for the session bean and local for the entity bean.

    Anyway, although these concepts can still exists, things have been much better simplified in EJB3.

    EDIT: In response to the comment, with EJB3, the bean class itself can implement the remote and the home interfaces directly (for the session beans). They are made EJB's with a single annotation. Stateful beans have a couple more annotations to deal with state issues. Entity beans do not have a Home interface, and do not need a local interface, you can interact with the java object directly. There is an EntityManager that retrieves the right entity beans based on a query, and that EntityManager is injected via an annotation.

    That kind of sums it up in a paragraph. There are great tutorials on the web for this stuff, but EJBs in general solve a class of problem that is hard to appreciate unless you deal with the problem. They aren't the only way to solve it, but unless you deal with this type of programming, just reading about it won't really help you relate to it.

    0 讨论(0)
提交回复
热议问题