Hi All,
I've figured it out. What I failed to see is that jboss.xml should bind the resource
reference name to the actual JNDI name of the resource.
To summarize, here is a combination that works well:
mysql-ds.xml
<?xml version="1.0" encoding="UTF-8"?>
| <datasources>
| <local-tx-datasource>
| <jndi-name>jdbc/myApp/myDB</jndi-name>
| <connection-url>jdbc:mysql://host:port/dbname</connection-url>
| <driver-class>com.mysql.jdbc.Driver</driver-class>
| <user-name>bla</user-name>
| <password>bla</password>
| </local-tx-datasource>
| </datasources>
jbosscmp-jdbc.xml
<?xml version="1.0" encoding="UTF-8"?>
| <jbosscmp-jdbc>
| <defaults>
| <datasource>java:/jdbc/myApp/myDB</datasource>
| <datasource-mapping>mySQL</datasource-mapping>
| </defaults>
| </jbosscmp-jdbc>
In ejb-jar.xml
...
| <resource-ref >
| <res-ref-name>jdbc/myDB</res-ref-name>
| <res-type>javax.sql.DataSource</res-type>
| <res-auth>Container</res-auth>
| </resource-ref>
| ...
The following snippet (in jboss.xml) needs to be placed in the descriptor of EJBs that
look up the data source in question:
...
| <resource-ref>
| <res-ref-name>jdbc/myDB</res-ref-name>
| <jndi-name>java:/jdbc/myApp/myDB</jndi-name>
| </resource-ref>
| ...
In Java code, the lookup is performed as follows:
...
| Context ictx = new InitialContext();
| DataSource myDS = (DataSource) ictx.lookup("java:comp/env/jdbc/myDB");
| ...
A few notes:
- The JNDI name jdbc/myApp/myDB is arbitrary. I intentionally used myApp in the middle
to make it different than the resource reference name jdbc/myDB used in EJBs.
- The JNDI name of the data source is declared in mysql-ds.xml. This name is
referenced in jbosscmp-jdbc.xml and jboss.xml with the java:/ prefix.
- The JNDI name can be used in the code, but in that case any change to it would
necessitate updating the Java code. By using resource reference names we insulate the
code from changes in the JNDI names, as the binding from the resource reference name
to the actual JNDI name is done in jboss.xml.
Thanks,
Alex
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3849906#3849906
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3849906
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user