You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by cpales <cp...@gmail.com> on 2013/11/27 12:43:12 UTC

Postgres XA transaction rollback

Hi,

I was considering using tomee for a small enterprise project of our company.
The main reason why I looked into tomee, is that our company has already
experience with the underlying technologies (tomcat, cxf, activemq, etc.)
So I was trying to set up a small pilot project to see, that all of our
project requirements are met.

The main setup of the pilot project: 2 postgres db's and tomee with 2 xa
datasources, 2 test web applications (to make a remote ejb call)
For test purposes a local EJB is injected in a simple servlet.
The local EJB executes the following sequence:
- persist a local entity to the first db
- call remote ejb which persist an entity to the second db
- throw a RuntimeException to test a rollback

The main problem is, that the remote persist isn't rolled back, despite of
the runtime exception, the second entity is always saved to the db.
Are xa transactions supported by tomee?
Actually I'm not even sure, that my xa datasource configuration is correct.

    <Resource id="PG1" class-name="org.postgresql.xa.PGXADataSource">
        databaseName test
        serverName localhost
        portNumber 5432
    </Resource>
    <Resource id="PG2" class-name="org.postgresql.xa.PGXADataSource">
        databaseName test2
        serverName localhost
        portNumber 5432
    </Resource>
    <Resource id="TestDSXA1" type="DataSource">
        XaDataSource PG1
        JtaManaged true
        UserName postgres
        Password pass
    </Resource>
    <Resource id="TestDSXA2" type="DataSource">
        XaDataSource PG2
        JtaManaged true
        UserName postgres
        Password pass
    </Resource>

I would be glad if somebody could point me into the right direction.

Thanks,
Csaba



--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by cpales <cp...@gmail.com>.
I'm pretty sure too, that the remote call has it's own transaction and can
commit on it's own. I just don't understand why the transaction isn't
propagated. The same setup works on jboss as expected.



--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666437.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by AndyG <an...@orprovision.com>.
No you're correct. Calling flush does just that, so a rollback is not
possible. That's what I was probing for , to make sure that was not the
case.

I do think that this.remoteService.test(); will be in it's own transactional
context and will not be affected by the rollback though? When
this.remoteService.test(); returns it has committed already.

Andy.



--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666434.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by cpales <cp...@gmail.com>.
I don't think I need to call an explicit flush here, but correct me if I'm
wrong.

The local EJB code:
@Stateless
public class TestServiceImpl {

    @PersistenceContext(unitName = "test-web")
    private EntityManager em;

    @EJB(mappedName = "jndi:ext://testProvider/Test2ServiceImplRemote")
    private TestService remoteService;

    public void test() {
        Test t = new Test();
        t.setTest("test");
        this.em.persist(t);
        this.remoteService.test(); //call remote service
        throw new RuntimeException("rollback pls!");
    }
}


The remote EJB:
@Stateless
public class Test2ServiceImpl implements TestService {

    @PersistenceContext(unitName = "test-remote-web")
    private EntityManager em;

    @Override
    public void test() {
        Test2 t = new Test2();
        t.setTest("test");
        this.em.persist(t);
    }
}




--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666432.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by AndyG <an...@orprovision.com>.
Could you share the relevant code for the persist? Are you calling 'flush' on
the EntityManager at all?

Andy.



--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666430.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by cpales <cp...@gmail.com>.
That was actually my original setup:

    <Resource id="TestDSXA1" type="DataSource">
        DataSourceCreator dbcp
        JdbcDriver org.postgresql.xa.PGXADataSource
        JdbcUrl
jdbc:postgresql://localhost:5432/test?user=postgres&amp;password=pass
        JtaManaged true
    </Resource>
...

But doesn't work either.



--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666436.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by Romain Manni-Bucau <rm...@gmail.com>.
No

what I meant (sorry I was not clear) I mean using:

<Resource id="..." type="DataSource">
....
JdbcDriver = org.postgresql.xa.PGXADataSource
</Resource>

BTW your conf seems ok (https://issues.apache.org/jira/browse/TOMEE-1049)
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/11/27 cpales <cp...@gmail.com>:
> I've already tried dbcp, even bonecp without any luck.
> How can I set up the iirc typed datasource?
> Do you mean:
>     <Resource id="PG1" class-name="org.postgresql.xa.PGXADataSource"
> type="iirc">
>         databaseName test
>         serverName localhost
>         portNumber 5432
>     </Resource>
>     <Resource id="TestDSXA1" type="DataSource">
>         DataSourceCreator dbcp
>         XaDataSource PG1
>         JtaManaged true
>         UserName postgres
>         Password pass
>     </Resource>
>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666433.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by cpales <cp...@gmail.com>.
I've already tried dbcp, even bonecp without any luck.
How can I set up the iirc typed datasource?
Do you mean:
    <Resource id="PG1" class-name="org.postgresql.xa.PGXADataSource"
type="iirc">
        databaseName test
        serverName localhost
        portNumber 5432
    </Resource>
    <Resource id="TestDSXA1" type="DataSource">
        DataSourceCreator dbcp
        XaDataSource PG1
        JtaManaged true
        UserName postgres
        Password pass
    </Resource>




--
View this message in context: http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429p4666433.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Postgres XA transaction rollback

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

Adding to DataSource with type=DataSource "DataSourceCreator=dbcp" should
make it working

You can also set as jdbc driver the xa datasource type iirc
Le 27 nov. 2013 12:45, "cpales" <cp...@gmail.com> a écrit :

> Hi,
>
> I was considering using tomee for a small enterprise project of our
> company.
> The main reason why I looked into tomee, is that our company has already
> experience with the underlying technologies (tomcat, cxf, activemq, etc.)
> So I was trying to set up a small pilot project to see, that all of our
> project requirements are met.
>
> The main setup of the pilot project: 2 postgres db's and tomee with 2 xa
> datasources, 2 test web applications (to make a remote ejb call)
> For test purposes a local EJB is injected in a simple servlet.
> The local EJB executes the following sequence:
> - persist a local entity to the first db
> - call remote ejb which persist an entity to the second db
> - throw a RuntimeException to test a rollback
>
> The main problem is, that the remote persist isn't rolled back, despite of
> the runtime exception, the second entity is always saved to the db.
> Are xa transactions supported by tomee?
> Actually I'm not even sure, that my xa datasource configuration is correct.
>
>     <Resource id="PG1" class-name="org.postgresql.xa.PGXADataSource">
>         databaseName test
>         serverName localhost
>         portNumber 5432
>     </Resource>
>     <Resource id="PG2" class-name="org.postgresql.xa.PGXADataSource">
>         databaseName test2
>         serverName localhost
>         portNumber 5432
>     </Resource>
>     <Resource id="TestDSXA1" type="DataSource">
>         XaDataSource PG1
>         JtaManaged true
>         UserName postgres
>         Password pass
>     </Resource>
>     <Resource id="TestDSXA2" type="DataSource">
>         XaDataSource PG2
>         JtaManaged true
>         UserName postgres
>         Password pass
>     </Resource>
>
> I would be glad if somebody could point me into the right direction.
>
> Thanks,
> Csaba
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Postgres-XA-transaction-rollback-tp4666429.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>