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])