I am calling flush on purpose, to be able to test, to force the data to be
written to the database (not committed).
Anyway, I changed my method to this:
@Transactional(REQUIRES_NEW)
public void addUser(User user) {
List users = em.createQuery("Select u From User
u").getResultList();
log.info("user count " + users.size());
em.persist(user);
users = em.createQuery("Select u From User u").getResultList();
log.info("user count " + users.size());
throw new RuntimeException("On Purpose");
}
Now I am not calling flush, but JPA will call it internally before running the
second select.
Still the problem persists, i.e. the record is created, transaction is not
rolled back.
From the logs:
2018-05-16T15:41:10,232 | INFO | RMI TCP Connection(3)-127.0.0.1 | arjuna
| 6 - org.ops4j.pax.logging.pax-logging-api - 1.10.1 |
ARJUNA012170: TransactionStatusManager started on port 54960 and host 127.0.0.1
with service com.arjuna.ats.arjuna.recovery.ActionStatusService
2018-05-16T15:41:10,238 | DEBUG | RMI TCP Connection(3)-127.0.0.1 |
JpaInterceptor | 48 - org.apache.aries.jpa.blueprint - 2.6.1
| PreCall for bean userService, method addUser
2018-05-16T15:41:10,239 | DEBUG | RMI TCP Connection(3)-127.0.0.1 |
EMSupplierImpl | 50 - org.apache.aries.jpa.support - 2.6.1 |
Creating EntityManager for persistence unit responderPersistenUnit,
coordination txInterceptor.org.data.UserService.addUser
2018-05-16T15:41:10,246 | INFO | RMI TCP Connection(3)-127.0.0.1 |
UserServiceImpl | 135 - org.data - 1.0.0.SNAPSHOT | user count 0
2018-05-16T15:41:10,290 | INFO | RMI TCP Connection(3)-127.0.0.1 |
UserServiceImpl | 135 - org.data - 1.0.0.SNAPSHOT | user count
1
2018-05-16T15:41:10,291 | DEBUG | RMI TCP Connection(3)-127.0.0.1 |
JpaInterceptor | 48 - org.apache.aries.jpa.blueprint - 2.6.1
| PostCallWithException for bean userService, method addUser
2018-05-16T15:41:10,307 | DEBUG | RMI TCP Connection(3)-127.0.0.1 |
EMSupplierImpl | 50 - org.apache.aries.jpa.support - 2.6.1 |
Coordination failed txInterceptor.org.data.UserService.addUser
2018-05-16T15:41:10,318 | DEBUG | RMI TCP Connection(3)-127.0.0.1 |
TxInterceptorImpl | 53 - org.apache.aries.transaction.blueprint
- 2.1.0 | Setting transaction to rollback only because of exception
Best regards,
Alex soto
> On May 16, 2018, at 3:34 PM, Jean-Baptiste Onofré <[email protected]> wrote:
>
> Are you sure about your code ? Flush looks weird to me and it seems you don't
> use container managed transaction.
>
> Regards
> JB
>
> On 16/05/2018 21:08, Alex Soto wrote:
>> Yes, same result. I even tried with Narayana Transaction Manager, and same
>> result.
>> Best regards,
>> Alex soto
>>> On May 16, 2018, at 2:56 PM, Jean-Baptiste Onofré <[email protected]
>>> <mailto:[email protected]>> wrote:
>>>
>>> Same behavior with RequiresNew ?
>>>
>>> Regards
>>> JB
>>>
>>> On 16/05/2018 19:44, Alex Soto wrote:
>>>> With Karaf version 4.2.0, Rollback is not working with MariaDB and InnoDB
>>>> tables.
>>>> I deployed these features (from Karaf’s enterprise repository):
>>>> <feature>aries-blueprint</feature>
>>>> <feature>transaction</feature>
>>>> <feature>jndi</feature>
>>>> <feature>jdbc</feature>
>>>> <feature>jpa</feature>
>>>> <feature>pax-jdbc-mariadb</feature>
>>>> <feature>pax-jdbc-config</feature>
>>>> <feature>pax-jdbc-pool-dbcp2</feature>
>>>> <feature>hibernate</feature>
>>>> My Data Source is configured in the file
>>>> /org.ops4j.datasource-responder.cfg/
>>>> osgi.jdbc.driver.name = mariadb
>>>> dataSourceName=responder
>>>> url
>>>> =
>>>> jdbc:mariadb://mariadb.local:3306/responder?characterEncoding=UTF-8&useServerPrepStmts=true&autocommit=false
>>>> user=XXXX
>>>> password=XXXX
>>>> databaseName=responder
>>>> #Pool Config
>>>> pool=dbcp2
>>>> xa=true
>>>> My persistence.xml:
>>>> <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="responderPersistenUnit"
>>>> transaction-type="JTA">
>>>>
>>>> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
>>>> <!-- Only used when transaction-type=JTA -->
>>>>
>>>> <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)</jta-data-source>
>>>> <!-- Only used when transaction-type=RESOURCE_LOCAL -->
>>>>
>>>> <non-jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=responder)</non-jta-data-source>
>>>> <properties>
>>>> <property name=“hibernate.dialect"
>>>> value="org.hibernate.dialect.MySQL5Dialect" />
>>>> <property name="hibernate.show_sql" value="true" />
>>>> <property name="hibernate.format_sql" value="true" />
>>>> <property name="hibernate.hbm2ddl.auto" value="none"/>
>>>> </properties>
>>>> </persistence-unit>
>>>> </persistence>
>>>> My blueprint.xml:
>>>> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>>>> xmlns:jpa="http://aries.apache.org/xmlns/jpa/v2.0.0"
>>>> xmlns:tx="http://aries.apache.org/xmlns/transactions/v2.0.0"
>>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
>>>> https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
>>>> <jpa:enable />
>>>> <tx:enable />
>>>> <bean id="userService" class="org.data.impl.UserServiceImpl" />
>>>> <service ref="userService" interface="org.data.UserService" />
>>>> </blueprint>
>>>> For testing I throw exception in my DAO:
>>>> @Transactional(REQUIRED)
>>>> public void addUser(User user) {
>>>> em.persist(user);
>>>> em.flush();
>>>> throw new RuntimeException("On Purpose");
>>>> }
>>>> I expect the record not to be in the table due to rollback of the
>>>> transaction, but it still shows up in my database table.
>>>> Best regards,
>>>> Alex soto