0

I'm building little framework for data processing with EJB 3.
I have Entity Access Object tier which abstracts from data source. Now I need some kind of factory which will give me right bean to query entities.

Is it safe to pass looked up through JNDI local bean interfaces as parameters to another local beans? Will each method invocation from this local interface be addressed to the same bean or each call will be passed to different stateless beans as in @EJB occasion?

Piotr Nowicki
  • 17,914
  • 8
  • 63
  • 82
Alex Povar
  • 4,890
  • 3
  • 29
  • 44

1 Answers1

1

You don't have any guarantee that using JNDI you will give you the same EJB instance, so it's the same as with dependency injection using @EJB or @Inject. The only difference between @EJB and JNDI lookup is the SFSB. In this case, the container is required to provide you new SFSB instance every time you use JNDI lookup.

However, in my opinion, in EJB 3.x and dependency injection era, it's more easy to understand the @EJB/@Inject annotation. No need to pass any object references, just define your dependencies (EJB collaborators) in each EJB using @EJB.

Piotr Nowicki
  • 17,914
  • 8
  • 63
  • 82
  • Yeah. DI is very usefull, but I have no idea about how to implement runtime service facade with it. Is there any ways? – Alex Povar Dec 23 '11 at 13:30
  • So, you're using runtime provided values (i.e. method parameter) to access given EJB? – Piotr Nowicki Dec 23 '11 at 13:35
  • Yes. I have two different stateless beans with same interface. And depending on user actions I need to choose one of them to process request. – Alex Povar Dec 23 '11 at 13:42
  • In such case, what would you think about this: http://stackoverflow.com/questions/7920123/inject-ejb-bean-based-on-conditions/7923159#7923159 or this: http://stackoverflow.com/questions/7927681/choose-ejb-to-be-injected-without-recompiling/7927814#7927814? – Piotr Nowicki Dec 23 '11 at 13:50
  • looks cool. but is it right to do so if I gonna to route each call to different bean? There are much more than two beans. I have a tier of objects which stores different entities. Some of them are complex and cannot be fetched with jpa only. Such entities fetched through special implemented EAOs, other entities are simply described with JPA and to access all them I can use one bean. Now I gonna decouple this tear from business logic. I need something like service locator or maybe registry to associate class with EAO which operate it. – Alex Povar Dec 23 '11 at 14:03