Skip to content

Association to mapped select that uses @Param arguments fails #649

@lkb2k

Description

@lkb2k

I was attempting to upgrade a project from an old version of mybatis (3.2.2) and ran into an issue where associations that select on multiple columns fail when the nested query uses @param annotations. The same queries work fine in 3.2.2. I have confirmed the problem exists in 3.2.8, 3.3.1 and 3.4.0.

MyBatis version

3.2.3 +

Database vendor and version

Any

Test case or example project

Pull request with failing test #648

Steps to reproduce

I have modified the existing complex column test suite to add a failing test case that uses an association to a mapped statement that uses @param annotations. Other than the query being defined in the java interface and using @param instead of being in the XML the test is the same as the existing scenarios.

Expected result

Test should pass and result should be identical to the query that uses XML.

Actual result

Test throws the following exception

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'firstName' not found. Available parameters are []
### The error may exist in org/apache/ibatis/submitted/complex_column/PersonMapper.java (best guess)
### The error may involve org.apache.ibatis.submitted.complex_column.PersonMapper.getComplexWithParamAttributes
### The error occurred while handling results
### SQL: SELECT id, firstName, lastName, parent_id, parent_firstName, parent_lastName FROM Person WHERE id = ?
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'firstName' not found. Available parameters are []

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions