Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

"Mapped Statements collection already contains value..." exception for insert with selectKey #291

Closed
@GoogleCodeExporter

Description

@GoogleCodeExporter
What version of the MyBatis are you using?
mybatis 3.0.5-SNAPSHOT
mybatis-spring 1.0.1-SNAPSHOT 

Please describe the problem.  Unit tests are best!

I have a mapping file with a select tag that has sql includes referencing other 
mapping files. 
When MyBatis parses that sql tag for the first time 
IncompleteStatementException is thrown because it can't resolve included 
references yet. As a result this select is added to the incomplete list (see 
org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext() for 
that logic).
That select tag is followed by an insert tag which uses selectKey to generate 
id. The logic for selectKey is in 
org.apache.ibatis.builder.xml.XMLStatementBuilder.SelectKeyHandler class. 
There selectKey statement is added to the configuration's mapped statements and 
then its owning insert statement is looked up using 
configuration.getMappedStatement(id) method. Unfortunately, this method tries 
to parse all incomplete statements. As a result it throws exception trying to 
parse the problematic select tag that was added previously and adds the 
selectKey's insert to the incomplete list because of that exception. When 
MyBatis tries to parse the next statement from the mapping file it also 
re-parses all incomplete statements. When it tries to parse the insert 
statement again it goes through the same logic and adds the same selectKey 
statement to configuration's mapped statements again. But that map doesn't 
allow duplicates, so java.lang.IllegalArgumentException: Mapped Statements 
collection already contains value... is thrown. 

What is the expected output? What do you see instead?


Please provide any additional information below.

For now I'm planning to move my insert before the problematic select statement. 
But, I think this problem can also be solved by adding selectKey's statement to 
the configuration's mapped statements only after its owning insert statement is 
parsed successfully. 
The other way to solve this issue would be to only parse the last  incomplete 
statement after selectKey is generated instead of parsing all of them.



Original issue reported on code.google.com by maxmed...@gmail.com on 31 Mar 2011 at 6:41

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions