Could not roll back JDBC transaction using postgresql in sharding-proxy
shardingsphere version: sharding-proxy dev database: postgresql
throw new RuntimeException in transaction rolled back error. example code:

print log: `Caused by: org.postgresql.util.PSQLException: Expected command status BEGIN, got . at org.postgresql.core.v3.QueryExecutorImpl$1.handleCommandStatus(QueryExecutorImpl.java:536) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.core.v3.QueryExecutorImpl.interpretCommandStatus(QueryExecutorImpl.java:2492) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2127) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143) ~[postgresql-42.2.5.jar:42.2.5] at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:132) ~[postgresql-42.2.5.jar:42.2.5] at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) ~[HikariCP-java7-2.4.11.jar:na] at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) ~[HikariCP-java7-2.4.11.jar:na] at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) ~[mybatis-3.4.2.jar:3.4.2] at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) ~[mybatis-3.4.2.jar:3.4.2] at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) ~[mybatis-3.4.2.jar:3.4.2] at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) ~[mybatis-3.4.2.jar:3.4.2] at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) ~[mybatis-3.4.2.jar:3.4.2] at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) ~[mybatis-3.4.2.jar:3.4.2] at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) ~[mybatis-3.4.2.jar:3.4.2] at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source) ~[na:na] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_221] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_221] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434) ~[mybatis-spring-1.3.0.jar:1.3.0] ... 47 common frames omitted
Could not roll back JDBC transaction; nested exception is java.sql.SQLException: Connection is closed`
see #3545, postgresql do not open XA set by default
I used the mybatis but did not set setAutoCommit (false)
code:
TransactionTypeHolder.set(TransactionType.XA);
jdbcTemplate.execute(new ConnectionCallback<Object>() {
@Override
public Object doInConnection(final Connection connection) throws SQLException, DataAccessException {
connection.setAutoCommit(false);
doInsert(connection);
printData(jdbcTemplate, "----------------- query all before commit ------------------");
connection.rollback();
printData(jdbcTemplate, "----------------- query all after rollback ------------------");
return null;
}
});`
Now. I use row-jdbc and set connection.setAutoCommit(false);
already **set max_prepared_transactions > 0**
It appear `org.postgresql.util.PSQLException: Expected command status BEGIN, got .
at org.postgresql.core.v3.QueryExecutorImpl$1.handleCommandStatus(QueryExecutorImpl.java:536)
at org.postgresql.core.v3.QueryExecutorImpl.interpretCommandStatus(QueryExecutorImpl.java:2492)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2127)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:143)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:120)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at org.apache.shardingsphere.example.transaction.xa.raw.jdbc.ExampleMainPg.doInsert(ExampleMainPg.java:108)
at org.apache.shardingsphere.example.transaction.xa.raw.jdbc.ExampleMainPg.access$000(ExampleMainPg.java:37)
at org.apache.shardingsphere.example.transaction.xa.raw.jdbc.ExampleMainPg$2.doInConnection(ExampleMainPg.java:91)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:353)
at org.apache.shardingsphere.example.transaction.xa.raw.jdbc.ExampleMainPg.process(ExampleMainPg.java:87)
at org.apache.shardingsphere.example.transaction.xa.raw.jdbc.ExampleMainPg.main(ExampleMainPg.java:53)
you should send sql sctl:set transaction_type=XA to proxy to switch transaction type
Yeah, the problem is configuration way error in my code.