Hello.

I am having a problem with transactions.

I want to have a client which use differents components at the same time. 
And in some cases i need to use differents methods of a componet. This last one is 
which i describe in this message, becouse of is the simple case.

The problem that i am having is when the las method fails there is not a rollback and 
if i see the DB the changes have been alread made.


My client application is like this:


public class AtlasClient {
    public static void main(String[] args) {
        System.setProperty("java.naming.factory.initial",
        "org.jnp.interfaces.NamingContextFactory");
        System.setProperty("java.naming.provider.url", args[0]);

        try {


            InitialContext context  = new InitialContext();
             Object ref = context.lookup("pgomez/ejb/Atlas");
             AtlasHome home = (AtlasHome)PortableRemoteObject.narrow(ref, 
AtlasHome.class);
            Atlas atlas = home.create();

            Country country;
            country = atlas.getCountry(1);
            country.setUpdateDate(new Date());
            atlas.update(country);

            country = new Country();
            country.setNombre("Country " + Math.random());
            atlas.createCountry(country);


            atlas.fail();
        } catch (NamingException e) {
            System.out.println("NamingException");
            e.printStackTrace();
        } catch (RemoteException e1) {
            System.out.println("RemoteException");
            e1.printStackTrace();
        } catch (CreateException e1) {
            System.out.println("CreateException");
            e1.printStackTrace();
        }
    }
}

The fail method throws a RunTimeException.
When i check the db the changes are there.



The component look like this:



    protected AtlasDAO dao;

    public void init()  {
       dao = new AtlasDAO();
    }

    public void destroy() {
        dao = null;
    }

    public void createCountry(Pais pais) {
        dao.createCountry(pais);
    }

    public void update(Country country) {
        dao.store(country);
    }

    public void fail() {
        throw new RunTimeException();
    }

    public Country getCountry(int id) {
        return dao.getCountry(id);
    }


In each DAO'S method i get the connection and i release the connection.
My DAO looks like this:

/** DAO Constructor */

private void AtlasDAO() {
        InitialContext context = new InitialContext();
    datasource = (DataSource) ic.lookup(JNDINames.ATLAS_DATASOURCE);
}


private void getDBConnection () {
        dbConnection = datasource.getConnection();
}

private void closeConnection() {
        dbConnection.close();
}

....

private Country getCountry(int id) throws DAOException {


        try {
                getDBConnection();
                 .....
                 .....
                 .....
        } catch (...) {

        } finally {
                closeResultSet(rs);
                closeStatement(stmt);
                closeConnection();
        }
}



The Atlas descriptor is:



  <enterprise-beans>
    <session>
      <ejb-name>pgomez/ejb/Atlas</ejb-name>
      <home>co.com.pragma.pgomez.atlas.ejb.AtlasHome</home>
      <remote>co.com.pragma.pgomez.atlas.ejb.Atlas</remote>
      <ejb-class>co.com.pragma.pgomez.atlas.ejb.AtlasEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      </session></enterprise-beans>
  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>pgomez/ejb/Atlas</ejb-name>
        <method-name>*</method-name>
      </method>
      <method>
        <ejb-name>pgomez/ejb/Atlas</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>*</method-name>
      </method>
      <method>
        <ejb-name>pgomez/ejb/Atlas</ejb-name>
        <method-intf>Home</method-intf>
        <method-name>*</method-name>
      </method>
      <trans-attribute>required</trans-attribute>
    </container-transaction>

  </assembly-descriptor>



My jboss.jcml is attached.
I only have change the JDBC stuff.

My DATABase:
Oracle 8.15

My Driver JDBC 
classes12.zip (From oracle)

My client os:
Windows NT 4.0


The jboss os:
It is runnig over solarix

The jdk:
1.3



Is possible what i want or not?

If no why not an if yes how can i do that?

Thanks a lot.


______________________________________
Message sent with Misiva
Visit us at http://www.pragma.com.co/misiva

Attached file 'jboss.jcml'

Reply via email to