org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4 Error creating lazy proxy

60 views
Skip to first unread message

郭大鹏

unread,
Dec 29, 2020, 6:34:13 AM12/29/20
to mybatis-user
Machine translation:
When I was testing fetchType="lazy", Error creating lazy Proxy appeared.
I don't know if I'm missing something.
I use a org org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4
After investigation, I found that mybatis fixed this problem when it was 3.5.0, but Now I'm using 3.5.6. I don't know why this problem is happening to me.
If you can confirm that there is no such problem on 3.5.6, I hope you can tell me and I will try to solve it by myself. I'm not sure if It's just me.

This is a demo of the code I'm testing
https://github.com/GuoDapeng/mybatis-demo

Here is the database file
doc/sql/database.sql

Here's another test
src/test/kotlin/icu/guodapeng/mybatisdemo/domain/UserRolesTests.kt

原文:
我在测试 fetchType="lazy" 的时候,出现了 Error creating lazy proxy。
我不清楚是不是我忽略了什么。
我使用的是 org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4
我调查得知,mybatis 3.5.0 的时候修复过这个问题,我现在用的是 3.5.6。我不知道这个问题为啥发生在我身上。
如果能确认 3.5.6 是没有这个问题的,希望能告诉我,我尝试自己解决。我现在不确定是不是只有我出现了问题。

这是我测试代码的demo

这里有数据库文件
doc/sql/database.sql

这里又一个测试
src/test/kotlin/icu/guodapeng/mybatisdemo/domain/UserRolesTests.kt

Iwao AVE!

unread,
Jan 2, 2021, 9:02:16 AM1/2/21
to mybatis-user
Hello,

The error message says 'UserBase is final'.
To achieve lazy-loading, MyBatis creates a dynamic proxy of `UserBase` class, so `UserBase` has to be non-final [1].
Replacing `data class UserBase` to `open class UserBase` seems to fix the problem.

[1] https://stackoverflow.com/q/16437323/1261766

Regards,
Iwao

--
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 mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/d392bad0-a6da-4764-a664-ded269cd59e1n%40googlegroups.com.

郭大鹏

unread,
Jan 3, 2021, 3:01:10 AM1/3/21
to mybatis-user
machine translation:
Thank you very much, your ideas helped me. I now use the kotlin All-open compiler plugin to solve the problem I encountered. I have pushed the complete code to GitHub.

原文:
非常感谢,你的思路帮助了我。我现在通过 kotlin All-open compiler plugin 解决了我遇到的问题。我已经把完整的代码推送到 GitHub 了。


kotlin-allopen.png
Reply all
Reply to author
Forward
0 new messages