title: How to create PostgreSQL savePoint with Reactor and Spring
body: <p><a href="https://r2dbc.io/spec/0.8.0.RC1/api/io/r2dbc/spi/Connection.html" rel="nofollow noreferrer">io.r2dbc.spi.Connection</a> and <a href="https://github.com/pgjdbc/r2dbc-postgresql/blob/main/src/main/java/io/r2dbc/postgresql/PostgresqlConnection.java" rel="nofollow noreferrer">PostgresqlConnection</a> have <code>createSavepoint</code>, <code>releaseSavepoint</code> and <code>rollbackTransactionToSavepoint</code> methods.
  How can I use these method by having <code>R2dbcTransactionManager</code> and <code>TransactionalOperator</code>?</p>
  <p>I want to create an idempotent service which tries to insert to a table, if a unique constraint is violated then selects the existing record and continues with that</p>
  <pre><code>Mono.just(newOrder)
      .flatMap(order -&gt; orderRepository.save(order)
          .onErrorResume(throwable -&gt; orderRepository.findByUniqueField(newOrder.uniqueField))
  
      .otherProcesses...
      .as(transactionalOperator::transactional)
  </code></pre>
  <p>And I receive <code>current transaction is aborted, commands ignored until end of transaction block</code> from PostgreSQL</p>
  <p>I saw this answer <a href="https://stackoverflow.com/a/48771320/5275087">https://stackoverflow.com/a/48771320/5275087</a> but it seams <code>autosave=always</code> doesn't work with r2dbc</p>
  <p>I wanted to try something like:</p>
  <pre><code>transactionalOperator.execute(reactiveTransaction -&gt; {
    GenericReactiveTransaction genericReactiveTransaction = (GenericReactiveTransaction) reactiveTransaction;
    ConnectionFactoryTransactionObject txObject = (ConnectionFactoryTransactionObject) genericReactiveTransaction.getTransaction();
    Connection connection = txObject.getConnectionHolder().getConnection();
    return Mono.from(connection.createSavepoint(TRANSACTION_LEVEL_1))
              .then(Mono.just(newOrder)
                  .flatMap(order -&gt; orderRepository.save(order)
                      .onErrorResume(throwable -&gt;
                          Mono.from(connection.rollbackTransactionToSavepoint(TRANSACTION_LEVEL_1))
                              .then(orderRepository.findByUniqueField(newOrder.uniqueField)))
                  ));
  </code></pre>
  <p>But <code>R2dbcTransactionManager.ConnectionFactoryTransactionObject</code> is a private class.</p>
  <p>How do I achieve this without using reflection</p>