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

kotlin使用mybatis plus的ktUpdate的setSql时 出现错误! #6261

Closed
xuxiaolong123 opened this issue Jun 17, 2024 · 4 comments
Closed

kotlin使用mybatis plus的ktUpdate的setSql时 出现错误! #6261

xuxiaolong123 opened this issue Jun 17, 2024 · 4 comments

Comments

@xuxiaolong123
Copy link

当前使用版本
3.5.5

当前环境信息
Java22 + Mysql8.0

描述bug现象
setSql中 kotlin代码到java代码过程中,kotlin的可变参数展开出现问题,导致java代码中接收到的参数的一个数组对象,而不是具体的参数,从而导致报错!!!

提供问题复现步骤
prescriptionMealService.ktUpdate()
.eq(AnPrescriptionMeal::id,entity.mealId)
.setSql("stop_count = stop_count + {0}",1).update();

kotlin使用mybatis plus的ktUpdate的setSql时 出现错误。

提供完整堆栈日志(可选)

SQL: UPDATE an_prescription_meal SET stop_count = stop_count + ? WHERE (id = ?)

Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '\xAC\xED\x00\x05ur\x00\x13[Ljava.lang.Object;\x90\xCEX\x9F\x10s)l\x02\x00\x00xp\x00\x00\x00\x01sr\x00\x11java.lang.Integer\x12\x'

; Data truncation: Truncated incorrect DOUBLE value: '\xAC\xED\x00\x05ur\x00\x13[Ljava.lang.Object;\x90\xCEX\x9F\x10s)l\x02\x00\x00xp\x00\x00\x00\x01sr\x00\x11java.lang.Integer\x12\x'
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:118)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:107)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:116)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:116)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439)
at jdk.proxy2/jdk.proxy2.$Proxy132.update(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:288)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:64)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:152)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at jdk.proxy2/jdk.proxy2.$Proxy248.update(Unknown Source)
at com.baomidou.mybatisplus.extension.conditions.update.ChainUpdate.lambda$update$eb4b7d7c$1(ChainUpdate.java:45)
at com.baomidou.mybatisplus.extension.conditions.ChainWrapper.execute(ChainWrapper.java:63)
at com.baomidou.mybatisplus.extension.conditions.update.ChainUpdate.update(ChainUpdate.java:45)
at com.baomidou.mybatisplus.extension.conditions.update.ChainUpdate.update(ChainUpdate.java:35)
at com.epzoon.enteral.service.impl.AnPrescriptionMealDetailServiceImpl.stop(AnPrescriptionMealDetailServiceImpl.kt:314)

@xuxiaolong123
Copy link
Author

如果不使用参数的写法,直接写死 例如:
prescriptionMealService.ktUpdate()
.eq(AnPrescriptionMeal::id,entity.mealId)
.setSql("stop_count = stop_count + 1").update();

又会报错
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Please check the syntax correctness! sql not contains: "{0}"
at com.baomidou.mybatisplus.core.toolkit.ExceptionUtils.mpe(ExceptionUtils.java:49)
at com.baomidou.mybatisplus.core.conditions.AbstractWrapper.formatSqlMaybeWithParam(AbstractWrapper.java:507)
at com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper.setSql(KtUpdateWrapper.kt:74)
at com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper.setSql(KtUpdateChainWrapper.kt:57)
at com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper.setSql(KtUpdateChainWrapper.kt:28)
at com.baomidou.mybatisplus.core.conditions.update.Update.setSql(Update.java:83)
at com.epzoon.enteral.service.impl.AnPrescriptionMealDetailServiceImpl.stop(AnPrescriptionMealDetailServiceImpl.kt:314)

@nieqiurong
Copy link
Contributor

提供复现工程.

@xuxiaolong123
Copy link
Author

xuxiaolong123 commented Jun 25, 2024

提供复现工程.
java22 + mysql8 + ruoyi 3.8.7 + springboot3.2.0 + mybatis-plus3.5.5 + kotlin1.9.20
1
2
这儿正确的结果应该是Object[0] 而不是Object[Object[0]]

@nieqiurong
Copy link
Contributor

81bcb97

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