• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class label dependency injection

 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The @EJB when used in class label its use to declare the JNDI name in its name attribute... right?

Now I am confused

In the below code can you please tell me why @PersistenceContext(name="persistence/InventoryAppMgr") is needed as
the code is doing lookup()

is without @PersistenceContext(name="persistence/InventoryAppMgr") lookup is not possible in SessionContext?



@PersistenceContext(name="persistence/InventoryAppMgr")
@Stateless
public class InventoryManagerBean implements InventoryManager {
@Resource SessionContext ctx;
public void updateInventory(...) {
...
// use context lookup to obtain container-managed entity
// manager
EntityManager em =(EntityManager)
ctx.lookup("persistence/InventoryAppMgr");
...
}
}
 
James Joshy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your EJB needs to refer to an resource, it need to declare it either in a) deployment descriptior or b) with annotations.
If you use the following code you would be using option b)
If you remove , you have to use the DD.. bujhle ?



@PersistenceContext(name="persistence/InventoryAppMgr")
 
Damodar Mukhopadhyay
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you... Bujhlam ...
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and i case of below code EntityManager will be registered to ENC and injected in em...Please verify if I am correct
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic