Mixing EJB and ADF
Loading an Application Module from a Message
Driven Bean:
Working with a mix of ADF and EJB technologies can sometimes be frustrating. One specific instance is trying to use an ADF BC Application Module from a Message Driven Bean. You can use ‿span class=SpellE>Configuration.createRootApplicationModule(‿‿ to load the application module in the following way:
public ApplicationModuleImpl
getApplicationModule() {
if(this.applicationModule == null) {
try {
String tp = "com.company.model.MobileService";
String
cfg = "MobileAppModuleLocal";
applicationModule = Configuration.createRootApplicationModule(tp, cfg);
} catch
(Exception e) {
e.printStackTrace();
applicationModule = null;
} }
return applicationModule; }
Code similar to the above can be used in the Message Driven Bean and is presented well in many samples on the internet. However you will still get the following errors if that is all you do:
javax.naming.NameNotFoundException: While trying to look up comp/env/jdbc/MobileDatabaseDS in‿o:p>
In order to avoid the above error
you will need to add a “resource-ref‿to your ejb-jar.xml file that references
in the data source. It would look
something like this:
<?xml version = '1.0'
encoding = 'ISO-8859-1'?>
<ejb-jar
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
version="3.0" xmlns="http://java.sun.com/xml/ns/javaee">
<enterprise-beans>
<message-driven>
<ejb-name>MobileTestBean</ejb-name>
<ejb-class> com.company.MobileTestBean
</ejb-class>
<resource-ref>
<res-ref-name>jdbc/MobileDatabaseDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</message-driven>
</enterprise-beans>
</ejb-jar>
I hope this is useful to someone. It stumped me for a day or two until I until I found an obscure reference in a forum with a vague answer posted after the poster found their own solution.
Enjoy,
John Jumper