Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lkb2k opened this issue Apr 21, 2016 · 1 comment
Closed

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

lkb2k opened this issue Apr 21, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@lkb2k
Copy link
Contributor

lkb2k commented Apr 21, 2016

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 []
@emacarron emacarron added the bug label Apr 25, 2016
@emacarron emacarron added this to the 3.4.1 milestone Apr 25, 2016
@emacarron emacarron self-assigned this Apr 25, 2016
@J-C-I-T
Copy link

J-C-I-T commented Jun 28, 2016

Hi emacarron, here i encounter a similar exception
Caused by: org.apache.ibatis.binding.BindingException: Parameter '_now' not found. Available parameters are [param1, domainId]

following is my case:

  1. Define a Mapper interface method call loadAllItemRecordWithDomain(@param(value = "domainId") String domainId)
  2. In corresponding Mapper.xml define the query statement and contains restriction:
    DOMAIN_ID=#{domainId} AND CREATED_ON > #{_now,jdbcType=DATE}
  3. Note: Here i will define a StatementInterceptor (annotation is : type = StatementHandler.class, method = "prepare") to initialize the _now parameter.

Note: In Mybatis_3.3.0 and 3.4.1 both are encounter same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants