-
1. Re: Problem with rollback a transaction
paul.robinson May 16, 2013 4:56 AM (in response to jerviver21)Jerson,
From your code above, it looks like it should do as you expect.
Can you provide your persistence.xml and your datasource configuration (either in your standalone.xml or maybe as a deployable datasource). It's possible that you are not using an XA datasource. In which case, I'm pretty sure the EntityManager will use a local transaction with your database and not participate in the JTA transaction.
Paul.
-
2. Re: Problem with rollback a transaction
jerviver21 May 16, 2013 10:52 AM (in response to paul.robinson)Thank you for the answer:
The configuration of datasource is:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
.......
<datasource jta="false" jndi-name="java:jboss/datasources/PostgreSQLDS" pool-name="PostgreSQLDS" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/medicaldb1</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql-9.1-901.jdbc4.jar</driver>
<security>
<user-name>postgres</user-name>
<password>pgsql</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
......
</datasources>
</subsystem>
And my persitence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MHPU" transaction-type="JTA">
<jta-data-source>java:/jboss/datasources/PostgreSQLDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
Perhaps is the datasource... jta=false... Let me check!!
-
3. Re: Problem with rollback a transaction
paul.robinson May 16, 2013 11:39 AM (in response to jerviver21)Jerson,
Yes, It looks to me like setting jta="true" would cause the datasource to use the JTA implementation, and thus solve your issue.
If you want to use multiple resources (e.g. another database or a message server) in the same transaction, you would need to configure an XA datasource. You could take a look at this discussion, It has an example of an XA PostgresSQL DS: https://community.jboss.org/thread/222474.
Paul.