[mybatis-generator; mybatis-dynamic-sql] How to get un-Preparing SQL from SelectStatementProvider?

classic Classic list List threaded Threaded
4 messages Options
Bin
Reply | Threaded
Open this post in threaded view
|

[mybatis-generator; mybatis-dynamic-sql] How to get un-Preparing SQL from SelectStatementProvider?

Bin
This is a example offer by official website for paging feature:

Mapper.java
@Select
({
       
"select id, isPublish",
       
"from t_lectures",
       
"${whereClauseProvider.whereClause}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffsetByOW(@Param("whereClauseProvider") WhereClauseProvider whereClause,
                                                 
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void testDemoGivingByOfficialWebsite(){
   
WhereClauseProvider whereClause = where(id, isEqualTo("id"))
           
.build()
           
.render(RenderingStrategy.MYBATIS3, "whereClauseProvider");

   
List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffsetByOW(whereClause, 5, 15);

    //println the result
    tLectures
.forEach(
           
(tLecture) -> {
               
try {
                   
objectMapper.writeValueAsString(tLectures);
               
} catch (JsonProcessingException e) {
                    e
.printStackTrace();
               
}
           
}
   
);
}

Yeah, it runs well.

And this is my example:
Mapper.java
@Select({
       
"${selectStatementProvider.selectStatement}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffset(@Param("selectStatementProvider") SelectStatementProvider selectStatement,
                                                   
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void selectByExampleWithLimitAndOffset() throws JsonProcessingException {
SelectStatementProvider selectStatement = select(id, ispublish)
.from(TLecturesDynamicSqlSupport.TLectures)
.where(id, isEqualTo("id"))
.orderBy(ispublish.descending())
.build()
.render(RenderingStrategy.MYBATIS3);

List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffset(selectStatement, 1, 1);
tLectures.forEach(
(tLecture) -> {
try {
objectMapper.writeValueAsString(tLectures);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
);
}

The difference between them is——I changed "org.mybatis.dynamic.sql.where.render.WhereClauseProvider" into "org.mybatis.dynamic.sql.select.render.SelectStatementProvider", and the latter cause BindingException like:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy125.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy218.selectByExampleWithLimitAndOffset(Unknown Source)
at com.remind.pharmacist.mapper.TLecturesMapperTest.selectByExampleWithLimitAndOffset(TLecturesMapperTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:145)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:115)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 35 more

It seem that the arguments in where clause didn't be prepared properly.Anyone who can help?Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [mybatis-generator; mybatis-dynamic-sql] How to get un-Preparing SQL from SelectStatementProvider?

Jeff Butler
Here's a gist that shows how to modify your Mapper and MapperTest:  https://gist.github.com/jeffgbutler/5df477b4f72f5461a8cc32fb7cf4669b

I believe this will work, please let me know if it doesn't.

Jeff Butler


On Wed, Mar 14, 2018 at 3:03 AM Bin <[hidden email]> wrote:
This is a example offer by official website for paging feature:

Mapper.java
@Select
({
       
"select id, isPublish",
       
"from t_lectures",
       
"${whereClauseProvider.whereClause}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffsetByOW(@Param("whereClauseProvider") WhereClauseProvider whereClause,
                                                 
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void testDemoGivingByOfficialWebsite(){
   
WhereClauseProvider whereClause = where(id, isEqualTo("id"))
           
.build()
           
.render(RenderingStrategy.MYBATIS3, "whereClauseProvider");

   
List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffsetByOW(whereClause, 5, 15);

    //println the result
    tLectures
.forEach(
           
(tLecture) -> {
               
try {
                   
objectMapper.writeValueAsString(tLectures);
               
} catch (JsonProcessingException e) {
                    e
.printStackTrace();
               
}
           
}
   
);
}

Yeah, it runs well.

And this is my example:
Mapper.java
@Select({
       
"${selectStatementProvider.selectStatement}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffset(@Param("selectStatementProvider") SelectStatementProvider selectStatement,
                                                   
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void selectByExampleWithLimitAndOffset() throws JsonProcessingException {
SelectStatementProvider selectStatement = select(id, ispublish)
.from(TLecturesDynamicSqlSupport.TLectures)
.where(id, isEqualTo("id"))
.orderBy(ispublish.descending())
.build()
.render(RenderingStrategy.MYBATIS3);

List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffset(selectStatement, 1, 1);
tLectures.forEach(
(tLecture) -> {
try {
objectMapper.writeValueAsString(tLectures);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
);
}

The difference between them is——I changed "org.mybatis.dynamic.sql.where.render.WhereClauseProvider" into "org.mybatis.dynamic.sql.select.render.SelectStatementProvider", and the latter cause BindingException like:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy125.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy218.selectByExampleWithLimitAndOffset(Unknown Source)
at com.remind.pharmacist.mapper.TLecturesMapperTest.selectByExampleWithLimitAndOffset(TLecturesMapperTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:145)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:115)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 35 more

It seem that the arguments in where clause didn't be prepared properly.Anyone who can help?Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Bin
Reply | Threaded
Open this post in threaded view
|

Re: [mybatis-generator; mybatis-dynamic-sql] How to get un-Preparing SQL from SelectStatementProvider?

Bin
Thanks for your comment! 

Unfortunately,it doesn't work well. Because "parameters" of SelectStatementProvider is a view here, therefore calling "put" method would cause java.lang.UnsupportedOperationException.




在 2018年3月14日星期三 UTC+8下午9:48:21,Jeff Butler写道:
Here's a gist that shows how to modify your Mapper and MapperTest:  <a href="https://gist.github.com/jeffgbutler/5df477b4f72f5461a8cc32fb7cf4669b" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fjeffgbutler%2F5df477b4f72f5461a8cc32fb7cf4669b\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlhz-0i3XwBxX-GBdArFX41xM0ng&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fjeffgbutler%2F5df477b4f72f5461a8cc32fb7cf4669b\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFlhz-0i3XwBxX-GBdArFX41xM0ng&#39;;return true;">https://gist.github.com/jeffgbutler/5df477b4f72f5461a8cc32fb7cf4669b

I believe this will work, please let me know if it doesn't.

Jeff Butler


On Wed, Mar 14, 2018 at 3:03 AM Bin <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="HXhUWixYAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">4733...@...> wrote:
This is a example offer by official website for paging feature:

Mapper.java
@Select
({
       
"select id, isPublish",
       
"from t_lectures",
       
"${whereClauseProvider.whereClause}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffsetByOW(@Param("whereClauseProvider") WhereClauseProvider whereClause,
                                                 
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void testDemoGivingByOfficialWebsite(){
   
WhereClauseProvider whereClause = where(id, isEqualTo("id"))
           
.build()
           
.render(RenderingStrategy.MYBATIS3, "whereClauseProvider");

   
List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffsetByOW(whereClause, 5, 15);

    //println the result
    tLectures
.forEach(
           
(tLecture) -> {
               
try {
                   
objectMapper.writeValueAsString(tLectures);
               
} catch (JsonProcessingException e) {
                    e
.printStackTrace();
               
}
           
}
   
);
}

Yeah, it runs well.

And this is my example:
Mapper.java
@Select({
       
"${selectStatementProvider.selectStatement}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffset(@Param("selectStatementProvider") SelectStatementProvider selectStatement,
                                                   
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void selectByExampleWithLimitAndOffset() throws JsonProcessingException {
SelectStatementProvider selectStatement = select(id, ispublish)
.from(TLecturesDynamicSqlSupport.TLectures)
.where(id, isEqualTo("id"))
.orderBy(ispublish.descending())
.build()
.render(RenderingStrategy.MYBATIS3);

List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffset(selectStatement, 1, 1);
tLectures.forEach(
(tLecture) -> {
try {
objectMapper.writeValueAsString(tLectures);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
);
}

The difference between them is——I changed "org.mybatis.dynamic.sql.where.render.WhereClauseProvider" into "org.mybatis.dynamic.sql.select.render.SelectStatementProvider", and the latter cause BindingException like:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy125.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy218.selectByExampleWithLimitAndOffset(Unknown Source)
at com.remind.pharmacist.mapper.TLecturesMapperTest.selectByExampleWithLimitAndOffset(TLecturesMapperTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:145)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:115)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 35 more

It seem that the arguments in where clause didn't be prepared properly.Anyone who can help?Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="HXhUWixYAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [mybatis-generator; mybatis-dynamic-sql] How to get un-Preparing SQL from SelectStatementProvider?

Jeff Butler
OK.  In the next version there's a better way to do this.  See this PR for details: https://github.com/mybatis/mybatis-dynamic-sql/pull/30

Jeff Butler


On Thu, Mar 15, 2018 at 5:50 AM Bin <[hidden email]> wrote:
Thanks for your comment! 

Unfortunately,it doesn't work well. Because "parameters" of SelectStatementProvider is a view here, therefore calling "put" method would cause java.lang.UnsupportedOperationException.




在 2018年3月14日星期三 UTC+8下午9:48:21,Jeff Butler写道:
Here's a gist that shows how to modify your Mapper and MapperTest:  https://gist.github.com/jeffgbutler/5df477b4f72f5461a8cc32fb7cf4669b

I believe this will work, please let me know if it doesn't.

Jeff Butler


On Wed, Mar 14, 2018 at 3:03 AM Bin <[hidden email]> wrote:
This is a example offer by official website for paging feature:

Mapper.java
@Select
({
       
"select id, isPublish",
       
"from t_lectures",
       
"${whereClauseProvider.whereClause}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffsetByOW(@Param("whereClauseProvider") WhereClauseProvider whereClause,
                                                 
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void testDemoGivingByOfficialWebsite(){
   
WhereClauseProvider whereClause = where(id, isEqualTo("id"))
           
.build()
           
.render(RenderingStrategy.MYBATIS3, "whereClauseProvider");

   
List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffsetByOW(whereClause, 5, 15);

    //println the result
    tLectures
.forEach(
           
(tLecture) -> {
               
try {
                   
objectMapper.writeValueAsString(tLectures);
               
} catch (JsonProcessingException e) {
                    e
.printStackTrace();
               
}
           
}
   
);
}

Yeah, it runs well.

And this is my example:
Mapper.java
@Select({
       
"${selectStatementProvider.selectStatement}",
       
"LIMIT #{limit,jdbcType=INTEGER} OFFSET #{offset,jdbcType=INTEGER}"
})
@ResultMap("TLecturesResult")
List<TLectures> selectByExampleWithLimitAndOffset(@Param("selectStatementProvider") SelectStatementProvider selectStatement,
                                                   
@Param("limit") int limit, @Param("offset") int offset);

MapperTest.java
@Test
public void selectByExampleWithLimitAndOffset() throws JsonProcessingException {
SelectStatementProvider selectStatement = select(id, ispublish)
.from(TLecturesDynamicSqlSupport.TLectures)
.where(id, isEqualTo("id"))
.orderBy(ispublish.descending())
.build()
.render(RenderingStrategy.MYBATIS3);

List<TLectures> tLectures = tLecturesMapper.selectByExampleWithLimitAndOffset(selectStatement, 1, 1);
tLectures.forEach(
(tLecture) -> {
try {
objectMapper.writeValueAsString(tLectures);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
);
}

The difference between them is——I changed "org.mybatis.dynamic.sql.where.render.WhereClauseProvider" into "org.mybatis.dynamic.sql.select.render.SelectStatementProvider", and the latter cause BindingException like:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy125.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy218.selectByExampleWithLimitAndOffset(Unknown Source)
at com.remind.pharmacist.mapper.TLecturesMapperTest.selectByExampleWithLimitAndOffset(TLecturesMapperTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameters' not found. Available parameters are [selectStatementProvider, offset, limit, param3, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.reflection.MetaObject.metaObjectForProperty(MetaObject.java:145)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:115)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433)
... 35 more

It seem that the arguments in where clause didn't be prepared properly.Anyone who can help?Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.