Try ConnectionDataSource instead of DriverManagerDataSource...this fixed my
transaction problems.

Also, use the resource location from your ejb-jar.xml. This was the resource
tag in your entity bean descriptor. You are looking up the plain vanilla
datasource. If you lookup a datasource directly (I never do this) you must
use the one that support transactions and pooling for an ejb (the
ejb-location) which is not in your datasource.

Here's a datasource for oracle:

        <data-source
                class="com.evermind.sql.DriverManagerDataSource"
 I use class="com.evermind.sql.ConnectionDataSource" much better at
transactions!

                name="MyDataSource"
                location="jdbc/MyCoreDS"
                xa-location="jdbc/xa/MyXADS"
                ejb-location="jdbc/MyDS"
                pooled-location="jdbc/MyPooledDS"
                connection-driver="oracle.jdbc.driver.OracleDriver"
                username="scott"
                password="tigger"
                url="jdbc:oracle:thin:@somecomputer:1521:ora"
                inactivity-timeout="30"
                max-connections="50"
                wait-timeout="5"
                schema="database-schemas/oracle.xml"
        />
</data-sources>
This is ok for a thin driver all the way, and no oci client.

Notice that your lookup is MyDSCore...this wouldn't really support
transactions or pooling. If you use the ejb-jar location, do a look on
ServerDataSource (if that's the resource name you gave your datasource in
the ejb-jar.xml)or whatever, and Orion pick the proper connection, the
ejb-location.

Regards,

the elephantwalker
www.elephantwalker.com

come join us, we are having a lively discussion on pooling and transaction
right now.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Tommy Wassgren
Sent: Wednesday, September 26, 2001 8:35 AM
To: Orion-Interest
Subject: Transactions for stateless SessionBeans


I'm using a data-source (Oracle) from a stateless session bean.
The session bean uses bean managed transactions (User transactions).
Reading and writing data to the Oracle database works fine.

The only problem is that when the ejb-transaction gets rolled back the
database transaction does not roll back.

Simplified example:

<i>
// Get the connection
Context context = new InitialContext();
ds = (DataSource)context.lookup("jdbc/MyDSCore");
Connection conn = ds.getConnection();
conn.setAutoCinnit(false);


try
{
   sessionContext.getUserTransaction().begin();

   conn.createStatement(.....);
   conn.executeUpdate();

   // If a rollback occurs here the data still gets updated

   ...
   sessionContext.getUserTransaction().commit();
}
catch(Exception e)
{
   e.printStackTrace();
   sessionContext.getUserTransaction().rollback();
}
</i>

My <b>data-sources.xml</b> looks like this:

<i>
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="MyDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
location="jdbc/MyDSCore"
username="scott"
password="tiger"
url="jdbc:oracle:thin:@SERVER:PORT:SID"
/>
</i>

Does anyone have any idea of why the transactions are not working
properly???


Reply via email to