Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there any point to creating some kind of cache for lookups in EJB3?

 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pre EJB3, I would typically cache the EJBHome lookups in a Map. In EJB3 it seems like you get back your interface directly from the jndi lookup and there is no need for the ejbhome.create() implementation. Is there anything to cache when doing things the EJB3 way, or does maybe the container take care of caching lookups behind the scenes?
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rick Reumann:
Pre EJB3, I would typically cache the EJBHome lookups in a Map. In EJB3 it seems like you get back your interface directly from the jndi lookup and there is no need for the ejbhome.create() implementation. Is there anything to cache when doing things the EJB3 way, or does maybe the container take care of caching lookups behind the scenes?


Hi Rick,

Not only will the container take care of the create, but it will also do the lookup, so you don't even need to go to JNDI. Just inject the EJB directly into your calling code using the @EJB annotation.
 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Keith:


Not only will the container take care of the create, but it will also do the lookup, so you don't even need to go to JNDI. Just inject the EJB directly into your calling code using the @EJB annotation.


As far as I know, using JBoss I can't use the @EJB annotation to inject an EJB into a non EJB object (like a servlet.) It also seems to only work for local EJBs. I guess I'll post on the jboss forums, unless someone else could provide some info..

from http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/injection/

Please note that EJB 3.0 dependency injection annotations only works in EJB objects -- not generic POJOs. For instance, you cannot use the dependency injection annotations in a servlet to obtain session bean objects. In addition, EJB 3.0 dependency injection only works in the local JNDI. Hence you cannot inject objects from remote servers.
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rick Reumann:


As far as I know, using JBoss I can't use the @EJB annotation to inject an EJB into a non EJB object (like a servlet.) It also seems to only work for local EJBs. I guess I'll post on the jboss forums, unless someone else could provide some info..

from http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/injection/

Please note that EJB 3.0 dependency injection annotations only works in EJB objects -- not generic POJOs. For instance, you cannot use the dependency injection annotations in a servlet to obtain session bean objects. In addition, EJB 3.0 dependency injection only works in the local JNDI. Hence you cannot inject objects from remote servers.


Then it isn't Java EE 5 compliant. The spec requires that injection of resources be allowed into the major component classes including servlets, EJBs, JSF beans, and so on. It doesn't make any sense if you can't inject an EJB into a servlet because then you are left having to do the old-style JNDI lookup and you are effectively stuck in EJB 2.1 land.

I guarantee that if you try it on Glassfish, OC4J or any other Java EE 5 server that supports it properly you'll see how easy it is to use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic