This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Persistence EntityManager injection from ejb-jar.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "Persistence EntityManager injection from ejb-jar.xml" Watch "Persistence EntityManager injection from ejb-jar.xml" New topic
Author

Persistence EntityManager injection from ejb-jar.xml

Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2729
    
    3

We can use the following syntax in EJB 3.0 to inject EntityManager



How can we do the above injection, by using the deployment descriptor?
(Please feel kind to specify all mandotary and optional elements (tags) and sub-elements)


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8210
    
  71


For injection to happen in EBJ3, you need to have annotations within your code. You won't be able to "inject" them through deployment descriptors. However, you will be able to bind objects to the ENC of the application through deployment descriptors (this has been there in earlier versions too). Later you can do a lookup in the JNDI for these objects.


[My Blog] [JavaRanch Journal]
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Hi,

in xml the injection looks like With exception of <persistence-context-ref-name> all elements are optional. The admissible values for <persistence-context-type> are "Container" and "Extended". The <injection-target> tag is responsible for the actual injection into the instance variable em.
[ November 02, 2008: Message edited by: Ralph Jaus ]

SCJP 5 (98%) - SCBCD 5 (98%)
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8210
    
  71

Ralph,

Thanks for posting I wasn't aware of this.
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2729
    
    3

Thank you Ralph Jaus
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2729
    
    3

Originally posted by Ralph Jaus:
Hi,

in xml the injection looks like


I have another question, why we use <injection-target-class> element? Is it should always same as to the <ejb-class> element under the given <session> element?
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Is it should always same as to the <ejb-class> element under the given <session> element?
dependency injection could also be used in superclasses of the bean class. I didn't check it, but I suppose that the <injection-target-class> serves this purpose and can contain the name of a superclass. Perhaps you can test it and let us know.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Persistence EntityManager injection from ejb-jar.xml
 
Similar Threads
Spring, in Spring-Struts-Hibernate application
Got NullPointer exception when injecting EntityManger
EntityManager in Servlets Doubt
Please help me understanding this piece of code
@EJB doing nothing - jboss-4.2.2.GA