davsclaus opened a new pull request, #28916: URL: https://github.com/apache/camel/pull/28916
Fixes [CAMEL-26145](https://issues.apache.org/jira/browse/CAMEL-26145). ### 1. With InOut, Insert/Update/Delete set the body to null **What was wrong:** `MyBatisProducer.doProcessResult` uses `exchange.getOut()` for an InOut exchange and copied the in body to it only when `outputHeader` was set. `Insert`, `InsertList`, `Update`, `UpdateList`, `Delete` and `DeleteList` put the result in the `CamelMyBatisResult` header only, so `requestBody("mybatis:insertAccount?statementType=Insert", account)` returned `null`. With InOnly the body was kept. **What changed:** the in body is always copied to the out message. `SelectOne`/`SelectList` still replace it with the result (unless `outputHeader` is set), so only the statement types that never set the body change. ### 2. An Insert with no body stores a row of nulls **What was wrong:** `doInsert` called `session.insert(statement)` without a parameter when the body (or the `inputHeader`) was null. A statement with placeholders such as `#{id}` inserted a row where every column was NULL, with no error. **What changed:** before that call the producer checks the mapped statement (`getBoundSql(null).getParameterMappings()`, which is what MyBatis itself runs for the insert). If it has parameters, it fails with `IllegalArgumentException: The message body is null, but the MyBatis statement insertAccount has parameters` (or names the input header). A statement without parameters still runs with a null body. ### Tests - New `MyBatisInOutKeepsBodyTest`: InOut for all six Insert/Update/Delete statement types keeps the body and sets the result header; SelectOne still sets the result as body. 6 of the 7 tests fail without the fix (the SelectOne one is a guard). - New `MyBatisInsertNullBodyTest`: null body and missing input header fail and insert nothing (both fail without the fix); a parameterless statement (new `insertDefaultAccount` in `Account.xml`) still inserts. - `MyBatisInsertWithRollbackTest` used a null body to trigger a NOT NULL violation. It now sends an `Account` without names, so it still tests the rollback on a `PersistenceException`. - `mvn -o clean install -Psourcecheck` in `components/camel-mybatis`: 66 tests, all pass. ### Docs - `mybatis-component.adoc` "Message Body" section notes InOut and the null body check; the catalog copy is updated. - Upgrade guide 4.24: new `camel-mybatis` entry for both behaviour changes. ### Not changed - `InsertList` with a null body: its statements use `<foreach>` over the list, which MyBatis already rejects for a null parameter. - `Update`/`Delete` with a null body run the statement with NULL parameters too; with a `WHERE id = #{id}` that matches no rows, so they do not create bad data the way an Insert does. Left as is to keep the change to the reported bug. - `mybatis-bean` uses `getMessage()` and is not affected by bug 1. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
