Skip to content

SpringManagedTransaction#close broken backward-compatibility between 1.3.x and 2.0.x #427

Closed
@SElab2019

Description

@SElab2019

When I try to upgrade mybatis-spring from 1.3.2 to the version after 2.0.0. The upgrade breaks my existing code when I extend SpringManagedTransaction and override method Close with SQLException. e.g.

public class Demo extends SpringManagedTransaction{
	private Connection connection;

	public Demo(DataSource dataSource) {
		super(dataSource);
	}

	@Override
	public void close() throws SQLException {
		try {
			if(connection != null){
				if(!TransactionSynchronizationManager.isSynchronizationActive()){
					if(connection.isReadOnly()){
						connection.setReadOnly(false);
					}
				}else if(!TransactionSynchronizationManager.isActualTransactionActive()){
					if(connection.isReadOnly()){
						connection.setReadOnly(false);
					}
				}
			}
		} catch (Exception e) {
			LOGGER.error("ha reset read only error:" + e.getMessage(), e);
		}
			
		super.close();
	}
}

The code should pass. However, it throws an error:

close() in Demo cannot override close() in org.mybatis.spring.transaction.SpringManagedTransaction
 overridden method does not throw java.sql.SQLException

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions