Discussions

EJB programming & troubleshooting: DataSource Lookup in JBoss

  1. DataSource Lookup in JBoss (3 messages)

    Hi All,
    How ao I lookup for the DataSource in JBoss? I created mysql-ds.xml and deployed on JBoss. When I start my JBoss I can see it getting bound as java:MasteringEJBPool. I am looking up for this DS like
    Context ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("java:MasteringEJBPool");
    return ds.getConnection();
    This works fine, but I am not able to understand how it is working?
    Is it going though my ejb-jar.xml & jboss.xml? Looks like no!!, if it is not how is it looking on my localhost?

    I would appreciate if someone can let me know how actually DS lookup works for EJBs on JBoss.
    Kind Regards,
    Gautham.

    Threaded Messages (3)

  2. well[ Go to top ]

    the 'java:/whatever' namespace is a namespace used by all the application server's components and only by them -

    when u deploy a data source (xxx-ds.xml)
    it is bound to the jndi name you gave him.

    and when you do a "new InitialContext()" you are actually using a set of properties configuring
    the jndi provider , classes etc e.g the jndi.properties file in the classpath(usually).

    refer to jboss's docs - it is well explained there...
  3. DataSource Lookup in JBoss[ Go to top ]

    Example for EJBs
    jboss.xml
    <?xml version="1.0" encoding="UTF-8"?>

    <jboss>
       <secure>false</secure>
       <enterprise-beans>
          <session>
             <ejb-name>gameBean</ejb-name>
             <jndi-name>ejb/gameBean</jndi-name>
             <clustered>false</clustered>
          </session>
       </enterprise-beans>
    </jboss>

    Java code:
    ctx = new InitialContext();
            gameBeanHome hm = PortableRemoteObject.narrow(ctx.lookup("ejb/gameBean"), gameBeanHome.class);


    for DataSource
    in xxx-ds.xml
     <local-tx-datasource>
        <jndi-name>OracleDS</jndi-name>
    <connection-url>jdbc:oracle:thin:@10.1.1.205:1521:devdb</connection-url>
    ---

    in java
    ctx = new InitialContext();
    ds = (javax.sql.DataSource) ctx.lookup("java:OracleDS");
  4. Re: DataSource Lookup in JBoss[ Go to top ]

    I developped the same thing and finally I a WrappedDataSource instead of a javax.sql.DataSource..and when I make a ds.getConnection(), it throws an exception : org.jboss.util.NestedSQLException: Problem locating real ConnectionManager: jboss.jca:service=LocalTxCM,name=MyDS; - nested throwable: (java.lang.IllegalStateException: No 'jboss' MBeanServer found!); - nested throwable: (Problem locating real ConnectionManager: jboss.jca:service=LocalTxCM,name=MyDS; - nested throwable: (java.lang.IllegalStateException: No 'jboss' MBeanServer found!)) at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94) at com.solutions.auto.persistence.connection.DBManager.getConnection(DBManager.java:133) the following instruction gives : System.out.println(" " + dataSource.getClass().getName()); org.jboss.ressource.adapter.jdbc.WrappedDataSource and the next one gives : System.out.println("Got datasource: " + dataSource.getConnection().getClass().getName()); org.jboss.ressource.adapter.jdbc.WrappedConnection Any idea about how to retrive a Connection ? thx in advance