• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rich Domain Model and Local JNDI Lookups

J J Wright
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm sure this is a problem a lot of other people have come across but there seems to be very little coherent discussion on the issue, so I'd very much appreciate any views people might have on the matter.

The problem is whether or not you compromise your object-oriented principles and stick with the EJB dependency injection annotations and a weak domain-model, or strive for a richer domain model with a sub-optimal JDNI lookup solution.

Take adding an item to simple shopping cart as an example.

The code above makes Cart dependent on Product and Price, when in reality Cart only cares about Order. The logic in the addItem method should really be in the Order object, but because Order is a POJO you can't inject the necessary EJB references. What's more, because the EJB interfaces are local they don't have a JNDI name assigned in the same way remote one would.

To perform a portable lookup of the required EJBs from within an instance of the Order class, the method must be invoked by a component with the required EJB references in its private namespace. See https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB. This makes for a very brittle solution with no compile time checks whatsoever.

The problem seems to have been addressed in EJB 3.1 as the proposal for Portable Global JNDI also applies to session beans exposing local only interfaces. See http://blogs.sun.com/kensaks/entry/portable_global_jndi_names.

There also seems to be very little guidance from Sun on this matter; ALL the examples in the JEE 5 Tutorial follow the weak domain model approach with business objects presented as little more than dumb placeholders for persistent data

What are people's thoughts on this? When it comes to EJB do we simply have to accept that local service lookups from POJOs aren't a viable option?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic