mybatis/mybatis-dynamic-sql

Support for collection mapping in JOIN Statements with Java annotations

tttol opened this issue · 2 comments

tttol commented

Are there any plans to support collection mapping in JOIN Statements with Java annotations?
I would like to complete it with just a .java file without using XML file.

It says below that it is not possible due to MyBatis limitation, but what exactly are MyBatis limitation?
Please tell me detal information.

https://mybatis.org/mybatis-dynamic-sql/docs/select.html#:~:text=If%20you%20are%20coding%20a%20join%2C%20it%20is%20likely%20you%20will%20need%20to%20code%20an%20XML%20mapper%20to%20define%20the%20result%20map.%20This%20is%20due%20to%20a%20MyBatis%20limitation%20%2D%20the%20annotations%20cannot%20define%20a%20collection%20mapping.%20If%20you%20have%20to%20do%20this%2C%20the%20Java%20code%20looks%20like%20this%3A

Here's a link to MyBatis docs where this is mentioned: https://mybatis.org/mybatis-3/java-api.html#:~:text=A%20mapping%20to%20a%20collection,not%20allow%20for%20circular%20references

Caution: You can accomplish annotation based collection mappings with lazy loading, but there are a lot of drawbacks to that approach because it causes multiple trips to the database and may make performance worse. However, I mention it because it is possible. Here's a Kotlin based example of lazy loading: https://github.com/jeffgbutler/mybatis-kotlin-examples/blob/master/src/main/kotlin/example04/lazy/Example04LazyMapper.kt

tttol commented

Thank you for the detailed information.
It's possible with lazy loading. However, if performance deteriorates, I think I'll stop using it.