Reputation: 2431
I am using spring data JPA to insert/update some data in an Oracle database. If I dont explicitly specify a dataSource
and/or a platformTransactionManager
, everything works great and I am able to insert/update data. If I specify DataSourceTransactionManager
as the platformTransactionManager
then no exceptions are thrown but the data is not inserted in the databse.
It seems like a commit issue. Using this datasource seems to require an explicit commit which is not happening and because of the that, the data is never actually persisted. I have tried specifying the spring.datasource.tomcat.defaultAutoCommit: true
but it didnt help.
Any ideas on how I can commit on completion of every transaction. My insert/update code looks like this
@Transactional
@Override
public OrderEntity save(OrderResponse order) {
OrderEntity o = orderRepository.unwrap(order);
return orderRepository.save(o);
}
transaction manager bean:
@Primary
@Bean
public PlatformTransactionManager txManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
--
Here is a sample project that demonstrates the issue. I am using h2 here and by simply adding the transactionManager
, data is not persisted anymore
Upvotes: 2
Views: 2112
Reputation: 2431
The problem was fixed by using jpaTransactionManager
because I think in this case, the dataSourceTransactionManager
was not tied to the entityManager
being used by JPA
Upvotes: 2