Here are two ways to set your default datasource, one is to add a jaws.xml
file to your application jar file with something like:
<jaws>
<datasource>OraclePool</datasource>
<type-mapping>Oracle</type-mapping>
</jaws>
The other more permanent and global option is to unjar jboss.jar, edit the
defaultjaws.xml file adding the middle two lines from above at the top, and
then rejar it back up. Of course this gives you a custom jboss.jar file
which might not be the best idea ever.
A third way is to set up resources in your ejb-jar.xml and jboss.xml file so
the beans are mapped to an explicit data source instead of the default data
source.
Add something like
<resource-ref>
<res-ref-name>jdbc/CartDs</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
to the entity bean descriptor in ejb-jar.xml.
Add something like
<resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
<res-name>jdbc/CartDs</res-name>
<res-jndi-name>OraclePool</res-jndi-name>
</resource-manager>
to the application jboss.xml.
Any of these should do the trick.
Cheers
-----Original Message-----
From: Richard Katz [mailto:[EMAIL PROTECTED]]
Sent: Monday, October 02, 2000 8:43 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [jBoss-User] Serious problem with driver and/or DataSource
addressing
Hi!
We are trying to get Oracle to work with jBoss 2.0 and we are getting
hit with
this problem that has us completely stuck and tied down. The problem
appears to be this:
No matter what we try to do, jBoss seems to execute something out of
the HyperSonic SQL driver instead of the Oracle driver.
The symptoms is always that the entity bean can not find its table in
the database. I have verified that the table is actually there, and
that JDBC can
get to it using a simple JDBC Servlet.
SYMPTOM EXAMPLES
==================
1. Pre-Minerva jBoss Example
Here is the output we get from jBoss pre-"Minerva" (that is before
Minerva was turned on for Hypersonic by default). I've numbered the
output lines below so that you can read them without getting lost:
------------------------------------------------------------------------
0 [Default] jBoss 2.0 Started
1 [Default] JRMPCI:invokeHome public abstract
2 com.hearme.admin.account.ejb.Account
3
com.hearme.admin.account.ejb.AccountHome.findByPrimaryKey(java.lang.String)
throws
javax.ejb.FinderException,java.rmi.RemoteException
4 [accountEJB] Found metadata for bean 'accountEJB' method is
findByPrimaryKey
5 [accountEJB] Datasource: org.jboss.jdbc.DataSourceImpl@2b6c89
6 [accountEJB] SQL State: S0002
7 [accountEJB] Action: executing query
8 [accountEJB] ps: org.hsql.jdbcPreparedStatement@3e0aba
9 [accountEJB] SQL Error Code: 0
10 [accountEJB] Cannot find Account w/id admin because of
:java.sql.SQLException: Table not found: S_TBL_ACCOUNTS in statement
11 [select AccountID from s_tbl_Accounts where AccountID = 'admin']
12 [accountEJB] exception occured while invoking finder
method:java.lang.reflect.InvocationTargetException
------------------------------------------------------------------------
Question: What is the meaning of line 8 above? It would appear to
indicate that something is executing in org.hsql instead of in Oracle.
Is this true?
2. Post-Minerva jBoss Example
In jBoss as it comes now, it has Minerva turned on for Hypersonic SQL.
Here's what I get using the latest jBoss:
------------------------------------------------------------------------
0. [Default] jBoss 2.0 BETA-PROD-01 Started
1. [Default] JRMPCI:invokeHome findByPrimaryKey
2. [Default] Tx is null
3. [Default] invokeHome
4. [accountEJB] TX_REQUIRED for findByPrimaryKey
5. [accountEJB] begin tx
6. [accountEJB] Datasource:
org.jboss.minerva.datasource.XAPoolDataSource@633e18
7. [accountEJB] SQL State: S0002
8. [accountEJB] Action: executing query
9. [accountEJB] ps: org.jboss.minerva.jdbc.PreparedStatementInPool@7bd0d
10. [accountEJB] SQL Error Code: 0
11. [accountEJB] Cannot find Account w/id admin because of
:java.sql.SQLException: T
able not found: S_TBL_ACCOUNTS in statement [select AccountID from
s_tbl_Account
s where AccountID = 'admin']
12. [accountEJB] rollback tx 0
13. [accountEJB] exception occured while invoking finder method; nested
exception is
: javax.ejb.EJBException
14. [Default] java.rmi.ServerException: exception occured while invoking
finder meth
od; nested exception is:
javax.ejb.EJBException
15. [Default] javax.ejb.EJBException
at
com.hearme.admin.account.ejb.AccountBean.ejbFindByPrimaryKey(AccountB
ean.java:355) at java.lang.reflect.Method.invoke(Native Method)
------------------------------------------------------------------------
Questions: 1. On line 9, it shows the same "ps:" kind of message as it
did on the previous example. Where does this "ps:" actually come from?
2. So why would it be running the PreparedStatement in minerva
XAPoolDataSource when minerva was not turned on for the Oracle data
source? (It is turned on for HyperSonic - by default). Again it
appears to be running on the HyperSonic data source and that the wrong
datasource - or the wrong driver has been selected instead of the Oracle
data source.
3. And finally, how should we name the data source?
- in jboss.conf we are using:
jdbc/talkserverDB
- in the Entity Bean: We are using
java:comp/env/jdbc/talkserverDB
Is this correct?
POSSIBLE JBOSS SOLUTIONS
========================
If we have not made some mistake in naming the data source, then it may
be that jBoss did not actually load the Oracle driver. Here's how this
may happen:
In org.jboss.jdbc.JdbcProvider.java
Line 61 should probably do the following
Class.forName(driver).newInstance();
instead of
Class.forName(driver);
The newInstance() is generally required by a number of databases -
inclulding Oracle. For some JDBC drivers you may have to do additional
work to ensure that the driver actually gets loaded.
WHAT WE DID DO ALREADY:
=========================
We did the following to ensure that the Oracle driver would load
1. Included the driver in jboss.properties.
jdbc.drivers=org.hsql.jdbcDriver,jdbc.idbDriver,oracle.jdbc.driver.OracleDri
ver
2. Inserted a data connection
<MLET CODE = "org.jboss.jdbc.DataSourceImpl"
ARCHIVE="jboss.jar,816classes12.zip" CODEBASE="../lib/ext/">
<ARG TYPE="java.lang.String"
VALUE="jdbc:oracle:thin:@talker.hearme.com:1521:ORA1">
<ARG TYPE="java.lang.String" VALUE="jdbc/talkserverDB">
<ARG TYPE="java.lang.String" VALUE="oracle.jdbc.driver.OracleDriver">
<ARG TYPE="java.lang.String" VALUE="xxx">
<ARG TYPE="java.lang.String" VALUE="yyy">
</MLET>
3. In the bean, we even tried to make sure that the Oracle driver is
loaded by doing
(Oracle used to require the registerDriver() at one point, although it
doesn't any more):
private Connection getConnection() throws SQLException {
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
DriverManager.registerDriver (new
oracle.jdbc.driver.OracleDriver());
}
catch (Exception e) {
log("Cannot load oracle driver :" + e);
throw new EJBException(e);
}
Oracle used to require the registerDriver() at one point, although it
doesn't any more. However, by the time this gets called, the
DataSourceImpl is possibly already associated with the wrong driver.
Many thanks for your help,
Rich Katz
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]