Hi Andre,
Thanks for the quick reply. Just tried it and still getting no joy. I'm sure
I'm missing something obvious...
-t
On Thu, Sep 21, 2000 at 07:13:09PM -0600, Andre Vanha wrote:
> Try using the XA datasource when you acquire a connection:
> jdbc/xa/myXADS
>
> In your ejb-jar file:
> <resource-ref>
> <res-ref-name>jdbc/myXADS</res-ref-name>
> <res-type>javax.sql.XADataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
> In your bean:
> Context naming = new InitialContext();
> XADataSource ds = (XADataSource)naming.lookup("java:comp/env/jdbc/myXADS");
> Connection conn = ds.getXAConnection().getConnection();
>
>
> I use an XADatasource with orcale and transactions work correctly.
> Also I read somewhere if you use JDBC from within EJBs you should use the
> EJBDS resource, however everything works fine for me with XADatasource.
> EJBDS might only be applicable to Entity Beans.
>
> Andre
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Tony Abbott
> Sent: Thursday, September 21, 2000 6:33 PM
> To: Orion-Interest
> Subject: container transactions not working...
>
>
> 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]
>
--
Tony Abbott [EMAIL PROTECTED]