Closed kihwankim closed 1 month ago
I think you probably know why those methods are nullable.
You might be wondering why the Kotlin JDSL doesn't support methods that return non-null types, and the reason is that Spring doesn't provide a method signature that returns non-null types.
Kotlin JDSL is not a wrapper library for JPA or Spring, but a support library, so by default the method signatures follow those of JPA and Spring.
However, neither of those libraries provide a method signature that returns a non-null type. Then Kotlin JDSL needs to define its own method signatures, which is not very user-friendly.
For example, when naming a method, Kotlin takes the non-null return type as the default and adds OrNull for nullable.
JPA, however, prefers the nullable return as the default. So, Kotlin JDSL should use method names like findAllNotNull or findNotNullAll. Since these method signatures are rarely seen in libraries written in Kotlin, it's hard for users to infer that these methods exist, so they have to search for them separately, which is not very user-friendly.
Also, if the returned list contains a null element, it's not clear what exception to throw. The repository provided by Spring throws the exceptions abstracted by Spring Data, except for invalid input values. However, it does not define which exception to throw if a non-null list contains a null element.
Kotlin JDSL can define and throw an exception, but as mentioned above, it's not very user-friendly because it's hard for the user to infer.
Kotlin JDSL did support methods like findFirstN in the Snapshot version. This is because it is inconvenient to set the limit using pageable. However, this has caused some people to experience issues. This is because they used fetch join for findFirstN. The findFirstN was created for the limit clause, but the person didn't realize that, and thought that it should be programmatically split into N pieces and returned.
As you can see, one method name can be seen differently by different people. Kotlin JDSL can't fit them all. I don't intend to force you to use a certain method signature, because Kotlin JDSL is a support library, not a wrapper library.
Please understand this.
Therefore, I recommend creating your own extension function to change List<T?> to List
fun <T : Any> List<T?>.mapNotNull(): List<T>
I didn't realize this. Thanks for finding this issue.
I will close this issue. If you have any additional questions, please reopen it.
I apologize for releasing this a month late.
Question 1
I wonder why are the generic types of all lists returned in KotlinJdslJpqlExecutor are all nullable var?? is there something reason??? cuz it would be useful to add not null list functions rather than only function nullable list return
Question 2
KotlinJdslJpqlExecutorImpl class has Transactional annotation but
readOnly
is false but I think thatfindAll
,findPage
... etc functions should be readOnly true