views:

909

answers:

2

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 investigation of scenario 3: “Exchange Request” suggests that two EJBs will provide a suitable solution: a session bean called EnterExchangeRequest to control the processing and an entity bean called ExchangeRequest to represent the persistent properties of the request. Discuss the role of the following interfaces:

  • Home
  • Remote
  • LocalHome
  • Local

and how they would provide access to the services of the EJBs described above.

I could try to explain how Home and Remote interfaces would fit into the picture. I have also heard the lecturer say one could replace Home by LocalHome, and Remote by Local (why?), but why are they asking me to discuss the role of all four at the same time?


Do I get it right when I say, the EJB container (the application server) would see that an interface is Home or Remote and then decide that the bean can 'live' on any machine in the cluster, while in the case the interfaces are LocalHome and Local the container will know that the beans can't be distributed across multiple machines and will therefore keep them 'alive' in one machine only?


I am totally lost in this enterprise Java jungle. I am experiencing a BeanOverflow. Could you please tell me which of my assumptions are wrong, point out my misconceptions and blunders.

Thank you all who are willing to help me with these EJB interfaces.

P.S. Note that I am not asking you to answer the question from the past exam paper. Just curious if you have any thoughts as to what could they be after when asking this.

+1  A: 

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.

Yishai
Could you please also provide a sketch of how things have been simplified in EJB3? That would be nice to know.
Peter Perháč
+1  A: 

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 JVM's.

I use a simular approach: I always deploy ears. Beans for the ear I make local beans, Beans meaned 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

Salandur