velocity-scripting
velocity-scripting copied to clipboard
Reference to outer parameter in nested repeat does not work
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
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?
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.
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 < [email protected]> 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/mybatis/velocity-scripting/issues/15#issuecomment-41856197 .
Frank D. Martínez M.