Problems trying to get a DataSource. It asks for a client
mtedone1 Jun 26, 2005 6:57 PMHi, I have got a Simple ServiceLocator which performs a lookup on a datasource and returns such datasource to a session bean (which then uses it to perform straight SQL).
During the lookup I get the following exception (also if I try to lookup the datasource from a plain java class):
javax.naming.NamingException: Failed to find j2ee.clientName in jndi env
This is the Datasource definition:
<?xml version="1.0" encoding="UTF-8"?> <!-- $Id: mysql-ds.xml,v 1.3 2004/09/15 14:37:40 loubyansky Exp $ --> <!-- Datasource config for MySQL using 3.0.9 available from: http://www.mysql.com/downloads/api-jdbc-stable.html --> <datasources> <local-tx-datasource> <jndi-name>JemosSiteDS</jndi-name> <connection-url>jdbc:mysql://localhost:3306/site</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>username</user-name> <password>password</password> <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource> </datasources>
And this is the bit of my service locator which performs the lookup (BTW, there are no problems with the JBoss JNDI context, as the other session and entity beans load fine):
public DataSource getDataSource(int service) throws ServiceLocatorException { //The return value DataSource ds = null; //Ensures that a datasource hasn't been stored for too long Integer serviceKey = new Integer(service); checkDatasourceCache(serviceKey); //If there is a Datasource in the cache for the required //service, returns it if (dataSourcesCache.containsKey(serviceKey)) { ds = (DataSource)dataSourcesCache.get(serviceKey); //Updates the timestamp for when this service was last used. synchronized(dataSourcesTimes) { dataSourcesTimes.put(serviceKey, new Date(System.currentTimeMillis())); } return ds; } //Gets the JBoss properties Properties props = getJBossPropertites(); try { ic = new InitialContext(props); ds = (DataSource)ic.lookup(getServiceName(service)); synchronized(dataSourcesCache) { dataSourcesCache.put(serviceKey, ds); dataSourcesTimes.put(serviceKey, new Date(System.currentTimeMillis())); } LOG.debug("Datasource " + getServiceName(service) + "" + " successfully retrieved."); } catch (NamingException e) { LOG.warn("An error occurred while trying to " + "create a JBoss context.", e); throw new ServiceLocatorException(e); } return ds; }
This is the value of the constant which I lookup:
java:/JemosSiteDS
I looked on the net and see that this problem can be solved by defining a client in the application-client.xml or jboss-client.xml, but I didn't understand how to do it, and why shall I do it. Why shall I declare a client for a Datasource which I want to search through the JNDI name?