Hi all,
I need again from your help, I'm facing the following issue,
Having a method annotated as transactional that samples data to the
database and assuming that we start with an Empty database
@Transactional(value = TxType.REQUIRED, rollbackOn = {
Exception.class })
public void sample() {
dao.persist(....)
dao.merge(....)
//here a find so that we make the provider to do a flush
to the DB as the flushmode is configured as AUTO
dao.find(.....)
//Now if I open the MySQLWorkbench I can see the
persisted/updated data even though the transaction it is not yet commited
//Do more operations
persist(....)
//We throw an exception to force a rollback
throw new RuntimeException("I want a rollback! :)")
}
Where DAO methods are of course annotated with @Transactional alike the
Sampler with REQUIRED and rollbackOn Exception.class. And Of course the
<tx:enable/> it is configured too in the DAO blueprint.
As you can assume in the DAO there is the em injected as specified in
the docu:
@PersistenceContext(unitName = "managed-jpa")
private EntityManager entityManager;
Using MySQL InnoDB as follows
<?xml version="1.0" encoding="UTF-8"?>
<blueprint default-activation="eager"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v2.0.0">
<bean id="dataSource"
class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
<property name="URL"
value="jdbc:mysql://localhost:3306/dbschema"/>
<property name="user" value="root" />
<property name="password" value="" />
</bean>
<service interface="javax.sql.DataSource" ref="dataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="jdbc/myds" />
</service-properties>
</service>
</blueprint>
And.. persistence unit
<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="managed-jpa" transaction-type="JTA">
<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/myds)</jta-data-source>
<properties>
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.archive.autodetection"
value="class" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="false" />
<property name="org.hibernate.flushMode" value="AUTO"/>
</properties>
</persistence-unit>
</persistence>
Considering that I do have transactional annotations activated:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://aries.apache.org/xmlns/transactions/v2.0.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/xmlns/transactions/v2.0.0
http://aries.apache.org/schemas/transaction/transactionv20.xsd">
<jpa:enable />
<tx:enable/>
Additionally, lets assume that we have a Synchronization registered to
the transaction so that afterCompletion and BeforeeCompletion are called.
So now my problem:
The transaction in before and after completion has
status 4 -rollback- as expected because of the exception I'm throwing in
the sampler, however there is no real rollback as I can still see the
data in the database -eg. using again the MySQL Workbench- perhaps
during the transaction the DB transaction was commited when the flush
was performed due to the call to 'find' in the sampler. Actually for me
it looks that somehow there is an autocommit when flush...
I was expecting that the fact of calling find during the transaction
-fires a flush- which does happen so that the find returns data
considering what already did happen during the transaction. However, I
wasn't expecting to see this data already in the MySQLWorkbench as that
is a different transaction. But more importantly I was expecting the
database to be empty at the end of the transaction due to the provoked
rollback
These are the jpa jta bundles I have
START LEVEL 6
ID|State |Level|Name
25|Active | 2|Apache Aries JPA blueprint (2.4.0)|2.4.0
38|Active | 2|Apache Aries JPA Container API (2.4.0)|2.4.0
40|Active | 2|Apache Aries JPA container (2.4.0)|2.4.0
50|Active | 2|Apache Aries JPA support (2.4.0)|2.4.0
g! lb transaction
START LEVEL 6
ID|State |Level|Name
23|Active | 2|Apache Aries Transaction Blueprint (1.1.1)|1.1.1
68|Active | 4|javax.transaction API (1.2.0)|1.2.0
104|Active | 2|Apache Aries Transaction Manager (1.3.0)|1.3.0
138|Active | 2|Apache Aries Transaction Blueprint (2.1.0)|2.1.0
I have running blueprint 1.1.1 and 2.1.0 but as noted in the blueprint
above, I'm using namespace 2.0 so the jpa blueprint 1.1.1 is not really
needed but anyway I have it running for testing purposes
Any hint about what I'm doing wrong?
Thank you!
regards
Pablo
--
WARNING: Computer viruses can be transmitted via email. The recipient should
check this email and any attachments for the presence of viruses. The company
accepts no liability for any damage caused by any virus transmitted by this
email. E-mail transmission cannot be guaranteed to be secure or error-free as
information could be intercepted, corrupted, lost, destroyed, arrive late or
incomplete, or contain viruses. The sender therefore does not accept liability
for any errors or omissions in the contents of this message, which arise as a
result of e-mail transmission.
Warning: Although the company has taken reasonable precautions to ensure no
viruses are present in this email, the company cannot accept responsibility for
any loss or damage arising from the use of this email or attachments.