This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Is there any point to creating some kind of cache for lookups in EJB3? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Is there any point to creating some kind of cache for lookups in EJB3?" Watch "Is there any point to creating some kind of cache for lookups in EJB3?" New topic
Author

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

Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
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

Joined: Jul 14, 2005
Posts: 304
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.


-Mike
Pro JPA 2: Mastering the Java Persistence API
Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
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

Joined: Jul 14, 2005
Posts: 304
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there any point to creating some kind of cache for lookups in EJB3?
 
Similar Threads
Disabling DNS caching
Needed: Alternative to JNDI to connect to LDAP
JCache
Caching EJB3 remote references prevents pooling or not
Location transparency in EJB?