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

Reference to outer parameter in nested repeat does not work #15

Open
tivv opened this issue Jan 29, 2014 · 3 comments
Open

Reference to outer parameter in nested repeat does not work #15

tivv opened this issue Jan 29, 2014 · 3 comments

Comments

@tivv
Copy link

tivv commented Jan 29, 2014

Mapper:

<update id="velocity-nested-ref" lang="velocity">
    #repeat( $_parameter.list $level1)
    #repeat( $level1 $level2)
    @{level1}
    #end
    #end
</update>

Test:

@Test
public void velocityTestNestedRef() throws SQLException, IOException {
    expect(connection.getAutoCommit()).andStubReturn(false);
    expect(connection.prepareStatement("\n" +
            "                        ?\n" +
            "                ?\n" +
            "                                ?\n" +
            "                ?\n" +
            "                    ")).andReturn(statement);

    replay();

    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(
            Resources.getResourceAsStream("configuration.xml"));
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, connection);
    List<List<Integer>> param = Arrays.asList(Arrays.asList(10,11),Arrays.asList(20, 21));
    sqlSession.insert("velocity-nested-ref", param);
    sqlSession.flushStatements();
    sqlSession.close();

}

Exception:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'level1' not found. Available parameters are [list]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: ?                 ?                                 ?                 ?
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'level1' not found. Available parameters are [list]
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:150)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:137)
    at com.luxoft.mybatis.splitter.UpdateSplitterPluginTest.velocityTestNestedRef(UpdateSplitterPluginTest.java:154)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:107)
    at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runTestMethod(UnitilsJUnit4TestClassRunner.java:174)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:88)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:96)
    at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:156)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:86)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
    at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
    at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
    at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:33)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:45)
    at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'level1' not found. Available parameters are [list]
    at org.apache.ibatis.session.defaults.DefaultSqlSession$StrictMap.get(DefaultSqlSession.java:257)
    at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:41)
    at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:113)
    at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:72)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:77)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:58)
    at org.apache.ibatis.executor.BatchExecutor.doUpdate(BatchExecutor.java:68)
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:100)
    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:148)
    ... 30 more
@mnesarco
Copy link
Member

Hi Tivv,

I am trying to verify this issue. $level1 is a list, so what is the intended output of @{level1} in your use case?

@tivv
Copy link
Author

tivv commented Apr 30, 2014

Well, it's a little too much simplified. Actual usage is when level1 is a bean and we try to get it's property from a nested repeat.

@mnesarco
Copy link
Member

Ok, I got it. It is a bit hard to fix it so fast because of the structure
of the code. I will do a major refactoring but it will take a while.

On Wed, Apr 30, 2014 at 4:55 PM, Vitalii Tymchyshyn <
notifications@github.com> wrote:

Well, it's a little too much simplified. Actual usage is when level1 is a
bean and we try to get it's property from a nested repeat.


Reply to this email directly or view it on GitHubhttps://github.com//issues/15#issuecomment-41856197
.

Frank D. Martínez M.

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

No branches or pull requests

2 participants