hi

hope someone can help me as i am now highly frustrated :) i am unable to get 
container managed transactions to work in conjunction with jdbc/oracle. 
basically i have a stateless session bean which writes to tables. It seems to
me orion is not managing the transactions at all. With the setup and code 
below it does not roll back the transaction despite the setRollbackOnly(). If 
I throw a system exception it does not roll back either. If I do multiple 
inserts in the method each insert is committed immediately and not as a single 
transaction at the end of the method. I'm really hoping I'm missing something 
obvious and this is not a serious problem in orion... Any help/suggestions 
would be highly appreciated!

I'm using Oracle 8.1.6R2, classes12.zip (Oracle JDBC drivers), JDK1.3rc1 on
Linux and have tried Orion 1.3.8 and 1.2.9 with the same results.

data-sources.xml:

        <data-source
                name="test"
                class="com.evermind.sql.ConnectionDataSource"
                location="jdbc/myDS"
                pooled-location="jdbc/myPooledDS"
                xa-location="jdbc/xa/myXADS"
                ejb-location="jdbc/myEJBDS"
                url="jdbc:oracle:oci8:@mydb"
                connection-driver="oracle.jdbc.driver.OracleDriver"
                username="user"
                password="password"
        />

and in ejb-jar.xml

      <session>
         <description>A session bean</description>
         <ejb-name>TestBean</ejb-name>
         <home>TestHome</home>
         <remote>Test</remote>
         <ejb-class>TestBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Container</transaction-type>
         <resource-ref>
            <res-ref-name>jdbc/myPooledDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
         </resource-ref>
      </session>
and
   <assembly-descriptor>
      <container-transaction>
         <method>
            <ejb-name>TestBean</ejb-name>
            <method-name>load</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
      </container-transaction>
   </assembly-descriptor>

and the method:

   public void load()
   {
      Connection con = null;
      PreparedStatement ps = null;
      try
      {
         Context naming = new InitialContext();
         DataSource ds = (DataSource)naming.lookup("java:comp/env/jdbc/myPooledDS");
         con = ds.getConnection();
         ps = con.prepareStatement("insert into mytable (id, value) values (?, ?)"):
         ps.setInt(1, 1);
         ps.setString(2, "testing");
         ps.executeUpdate();
         context.setRollbackOnly();
      }
      catch (NamingException e)
      {
         throw new EJBException(e);
      }
      catch (SQLException e)
      {
         throw new EJBException(e);
      }
      finally
      {
         try
         {
            if (ps != null)
               ps.close();
            if (con != null)
               con.close();
         }
         catch (SQLException e)
         {
            e.printStackTrace();
         }
      }
   }






-- 

   Tony Abbott                          [EMAIL PROTECTED]


Reply via email to