Okay, you have a number of issues.

1) If you do not use a jboss.xml file in your EJB JAR, then any data
source references get bound to the first database pool created.  That is
why you are getting Hypersonic connections instead of InstantDB
connections if you have several pools in jboss.conf and jboss.jcml.

2) If you declare a resource reference in your ejb-jar.xml with the name
"jdbc/Foo", you must look it up in your bean under the name
"java:comp/env/jdbc/Foo" not "jdbc/Foo".

3) What you really want to do is pick some constant name for the pool you
declare in jboss.conf and jboss.jcml (say, Foo).  Then name the resource
reference anything you want - "jdbc/BeanDatabase" or whatever.  Then
create a jboss.xml and create a resource manager that refers to the pool
you declared (Foo), with any name you want (say, Bar).  Then for each
bean, add an entry that links the resource reference name from ejb-jar.xml
(jdbc/BeanDatabase) to the resource manager (Bar).  You can have a number
of different beans, all with different DB names according to the
ejb-jar.xml file, but make them all refer to the same resource manager -
or have them all refer to different ones.  Whatever.  But to finish the
example, you now have "jdbc/BeanDatabase" (in ejb-jar.xml) linked to
resource manager "Bar" (in jboss.xml), which refers to "Foo" (in
jboss.xml), which was declared in jboss.conf and jboss.jcml.  If you leave
out jboss.xml, then every resource reference is linked to the first
database to be declared, no matter what the names are.

Aaron


On Fri, 13 Oct 2000, Marko [iso-8859-1] �trukelj wrote:
> Hi,
> 
> I've been experiencing some very unusual behavior when trying to set up a connection 
>pool to connect to MS SQL, so I played
> around a little in order to determine if it's got to do with the driver. It turns 
>out it does not - it looks as if something is
> wrong with name binding:
> 
> 
> Here is what I do and what happens:
> 
> 1) I clear entries for Hypersonic and InstantDB from jboss.conf
> 2) I set up my connection pool:
> 
> <MLET CODE="org.jboss.jdbc.XADataSourceLoader" ARCHIVE="jboss.jar" 
>CODEBASE="../lib/ext/">
>     <ARG TYPE="java.lang.String" VALUE="myDB">
>     <ARG TYPE="java.lang.String" VALUE="org.jboss.minerva.xa.XADataSourceImpl">
> </MLET>
> 
> 
> 3) I add this to jboss.jcml, meaning this is a pool to InstantDb
> 
>      <mbean name="DefaultDomain:service=XADataSource,name=myDB">
>        <attribute name="URL">jdbc:idb:../conf/instantdb.properties</attribute>
>        <attribute name="Password" />
>        <attribute name="JDBCUser">sa</attribute>
>      </mbean>
> 
> 
> 4) In my stateless session bean I define a business method that uses this datasource:
> 
>    public int testConnection()
>     {
> 
>         System.out.println("MyStatelessSessionBean.testConnection() called");
>         Connection connection = null;
> 
>         try {
>            DriverManager.setLogStream(System.out); // to create more info
>                                   // for technical support
>                                    //set a timeout for login and query
>            DriverManager.setLoginTimeout(10);
>            Context ctx = new InitialContext();
> 
> 
>            DataSource ds = (DataSource)ctx.lookup("java:comp/env/myDB");
>            connection = ds.getConnection();
> 
>            System.out.println("Retrieved connection from pool.");
>            DatabaseMetaData conMD = connection.getMetaData();
>            System.out.println("Driver Name:\t"    + conMD.getDriverName());
>            System.out.println("Driver Version:\t" + conMD.getDriverVersion());
> 
>         } catch(NamingException ne) {
>          System.out.println("Exception occured: " + ne.toString());
>         } catch(SQLException se) {
>          System.out.println("Exception occured: " + se.toString());
>         } finally {
>           if(connection != null)
>             try {connection.close();} catch(SQLException e) {}
>         }
> 
> 
>         return 1;
>     }
> 
> 
> 5) In deployment descriptor I add resource reference:
> 
>       <session>
>             <description>Test bean that uses connexion pool</description>
>             <ejb-name>myejb.MyStatelessSession</ejb-name>
>             <home>my.ejb.test.MyStatelessSessionHome</home>
>             <remote>my.ejb.test.MyStatelessSession</remote>
>             <ejb-class>my.ejb.test.MyStatelessSessionBean</ejb-class>
>             <session-type>Stateless</session-type>
>             <transaction-type>Bean</transaction-type>
>             <resource-ref>
>                 <description>A jdbc connection for you to test connection 
>pools</description>
>                 <res-ref-name>myDB</res-ref-name>
>                 <res-type>javax.sql.DataSource</res-type>
>                 <res-auth>Container</res-auth>
>             </resource-ref>
> 
>         </session>
> 
> 
> 6) I compile and jar MyStatelessSessionBean and put it in /deploy
> 
> 7) I start jboss.
> 
> 
> Now I start a client that creates myejb.MyStatelessSession remote object.
> And calls its testConnection() method.
> 
> 
> Everything works as expected. Info output in testConnection() tells me
> I got InstantDB connection.
> 
> <checkpoint1:>
> 
> Now I change all myDB names into jdbc/myDB . everywhere - in my bean
> in ejb-jar.xml, in jboss.conf and in jboss.jcml. I restart jboss. I
> recompile, repackage and redeploy the bean. I run the client and it
> tells me: 'name not bound:  jdbc'.
> 
> Ok, maybe there's a trick to it and I don't know to configure
> namebinding properly. So I go back to the state as it was on
> <checkpoint1> (myDB instead of jdbc/myDB) and continue from there.
> 
> 
> Now... I put XADataSourceLoader MLETs for Hypersonic and InstantDB back into 
>jboss.conf (right after myDB definition):
> 
> <MLET CODE="org.jboss.jdbc.XADataSourceLoader" ARCHIVE="jboss.jar" 
>CODEBASE="../lib/ext/">
>     <ARG TYPE="java.lang.String" VALUE="InstantDB">
>     <ARG TYPE="java.lang.String" VALUE="org.jboss.minerva.xa.XADataSourceImpl">
> </MLET>
> 
> <MLET CODE="org.jboss.jdbc.XADataSourceLoader" ARCHIVE="jboss.jar" 
>CODEBASE="../lib/ext/">
>     <ARG TYPE="java.lang.String" VALUE="Hypersonic">
>     <ARG TYPE="java.lang.String" VALUE="org.jboss.minerva.xa.XADataSourceImpl">
> </MLET>
> 
> I also add their corresponding configurations into jboss.jcml.
> 
> I restart jboss.
> 
> I run my client again. And it tells me it got connection to HypersonicSQL.  I should 
>get connection to InstantDB since I
> changed nothing in myDB configuration.
> 
> Something is definately wrong here. Looks as if Hypersonic pool is suddenly bound to 
>java:comp/env/myDB.
> 
> 
> (I'm using BETA_PROD_02, but the same problem was with BETA_PROD_01.)
> 
> 
> 
> Anyone?
> 
> 
> Regards,
> 
>    Marko Strukelj ([EMAIL PROTECTED])
> 
> 
> 
> 


Reply via email to