Skip to content

SimpleJdbcInsert mixes column names from different databases in MySQL [SPR-17483] #22015

@spring-projects-issues

Description

@spring-projects-issues

Hans Desmet opened SPR-17483 and commented

The script createDatabases.sql creates two MySQL databases: example1 and example2.
Each database has as table persons:

  • The database example1 has as column firstname in this table.
  • The database example2 has as column lastname in this table.

The test SimpleJdbcInsertTest tries to insert a record in the database example1.

@RunWith(SpringRunner.class)
@JdbcTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class SimpleJdbcInsertTest {
	@Autowired
	private DataSource dataSource;
	private SimpleJdbcInsert insert;

	@Before
	public void before() {
		insert = new SimpleJdbcInsert(dataSource);
	}

	@Test
	public void insertPerson() {
		insert.withTableName("persons");
		insert.execute(Collections.singletonMap("firstname", "joe"));
	}
}

The test fails, because SimpleJdbcInsert sends following statement to the database:

INSERT INTO persons (lastname) VALUES(?)

This statement uses the wrong column lastname from the other database: example2.

The example project uses Spring Boot 2.1.0
When you revert to Spring Boot 2.0.6, the code works.

I think the problem is caused by the way the MySQL JDBC driver 8.0.13 provides meta data has changed, compared to the driver 5.1.47.
I have tried to indiciate this in the test ColumNames, provided in the project.


Affects: 5.1.2

Reference URL: https://github.com/desmethans/simplejdbcinsert.git

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions