spring-data-jpaspring-integrationspring-integration-jdbc

JDBCMetadataStore vs transaction manager


As per documentation, JDBCMetadataStore requires an instance of DataSourceTransactionManager and this makes sense. What if I'm using JPA as primary transaction manager in the application? How can I tell to JDBCMetadataStore which transaction manager it should make use when calling the @Transactional methods - assuming I have to have 2 flavours of transaction manager beans in the application. Suggestions are welcome!


Solution

  • I suggest you to extend that JdbcMetadataStore and override all the transactional methods with delegation to super and @Transactional with the specific TX manager:

    public class MyJdbcMetadataStore extends JdbcMetadataStore {
    
        public MyJdbcMetadataStore(DataSource dataSource) {
            super(dataSource);
        }
    
        @Override
        @Transactional("jdbcTransactionManager")
        public String putIfAbsent(String key, String value) {
            return super.putIfAbsent(key, value);
        }
    
    }