@@ -204,8 +204,8 @@ mapping if you so desire.
204
204
205
205
Starting with version 1.5.2, we made a change to the rendering rules for the "in" conditions. This was done to limit the
206
206
danger of conditions failing to render and thus affecting more rows than expected. For the base conditions ("isIn",
207
- "isNotIn", etc.), if the list of values is empty, then the condition will still render, but the resulting SQL will
208
- be invalid and will cause a runtime exception. We believe this is the safest outcome. For example, suppose
207
+ "isNotIn", etc.), if the list of values is empty, then the library will throw
208
+ ` org.mybatis.dynamic.sql. exception.InvalidSqlException ` . We believe this is the safest outcome. For example, suppose
209
209
a DELETE statement was coded as follows:
210
210
211
211
``` java
@@ -214,12 +214,6 @@ a DELETE statement was coded as follows:
214
214
.and(id, isIn(Collections . emptyList()));
215
215
```
216
216
217
- This statement will be rendered as follows:
218
-
219
- ``` sql
220
- delete from foo where status = ? and id in ()
221
- ```
222
-
223
217
This will cause a runtime error due to invalid SQL, but it eliminates the possibility of deleting ALL rows with
224
218
active status. If you want to allow the "in" condition to drop from the SQL if the list is empty, then use the
225
219
"inWhenPresent" condition.
@@ -229,8 +223,8 @@ and the case-insensitive versions of these conditions:
229
223
230
224
| Input | Effect |
231
225
| ------------------------------------------| -----------------------------------------------------------------------------------|
232
- | isIn(null) | NullPointerException |
233
- | isIn(Collections.emptyList()) | Rendered as "in ()" (Invalid SQL) |
226
+ | isIn(null) | NullPointerException thrown |
227
+ | isIn(Collections.emptyList()) | InvalidSqlException thrown |
234
228
| isIn(2, 3, null) | Rendered as "in (?, ?, ?)" (Parameter values are 2, 3, and null) |
235
229
| isInWhenPresent(null) | Condition Not Rendered |
236
230
| isInWhenPresent(Collections.emptyList()) | Condition Not Rendered |
0 commit comments