|
Hi All, I have created a data source and I tried to
look up this from a standalone java class like this: try { Context
jndiCntx = new InitialContext(); DataSource ds = (DataSource) jndiCntx.lookup("MyDatasource"); DataSource ds = (DataSource)obj; System.out.println("Connected ….. "); return ds.getConnection(); } catch (Exception e) { e.printStackTrace(); } My class path has jndi.properties
for Geronimo and I am getting following exception in my class. javax.naming.NameNotFoundException: /MyDatasource not found at org.openejb.client.JNDIContext.lookup(JNDIContext.java:257) at javax.naming.InitialContext.lookup(InitialContext.java:361) And this is the server side error: ERROR [ContainerIndex]
contianerId is not a valid ObjectName:
MyDatasource But I was able to lookup this data source from
an entity bean like: new InitialContext().lookup("java:comp/env/jdbc/MyExampleDS "); This the openejb-jar.xml
for my EJB <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar" xmlns:naming="http://geronimo.apache.org/xml/ns/naming" xmlns:security="http://geronimo.apache.org/xml/ns/security" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment" configId="geronimo/CustomerEJB/1.0/car" parentId="geronimo/system-database/1.0/car"> <enterprise-beans> <entity> <ejb-name>CustomerEJB</ejb-name> <jndi-name>CustomerHomeRemote</jndi-name>
<local-jndi-name>CustomerRemote</local-jndi-name> <resource-ref>
<ref-name>jdbc/MyExampleDS</ref-name>
<resource-link>MyDatasource</resource-link>
</resource-ref> </entity> </enterprise-beans> </openejb-jar> Could any one explain me the differences
between two attempts? This is the data source deployment plan. <?xml
version="1.0"?> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
configId="MyDatasource"
parentId="geronimo/j2ee-server/1.0/car"> <dependency> <groupId>mysql</groupId> <artifactId>mysql</artifactId> <version>3.0</version> </dependency> <resourceadapter>
<outbound-resourceadapter> <connection-definition> <connectionfactory-interface> javax.sql.DataSource </connectionfactory-interface> <connectiondefinition-instance> <name>MyDatasource</name> <config-property-setting name="UserName">
xmeta
</config-property-setting> <config-property-setting name="Password">
xmeta
</config-property-setting> <config-property-setting name="Driver">
com.mysql.jdbc.Driver
</config-property-setting> <config-property-setting name="ConnectionURL">
jdbc:mysql://localhost:3306/xmeta
</config-property-setting> <config-property-setting name="CommitBeforeAutocommit">
false
</config-property-setting> <config-property-setting name="ExceptionSorterClass">
org.tranql.connector.NoExceptionsAreFatalSorter
</config-property-setting> <connectionmanager>
<local-transaction/>
<single-pool>
<max-size>10</max-size>
<min-size>1</min-size> <blocking-timeout-milliseconds>
5000
</blocking-timeout-milliseconds>
<idle-timeout-minutes>
30
</idle-timeout-minutes>
<match-one/>
</single-pool>
</connectionmanager> </connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter> </resourceadapter> </connector> Thanks, Siraj |
