Ask HN: How do you test your MyBatis dynamic SQL queries?
I’m currently working on a project using MyBatis, and one of the biggest friction points for me is verifying dynamic SQL. Whenever I have a complex query with <foreach>, <if>, or OGNL expressions, the feedback loop is painfully slow.
My current "workflow" (which I find incredibly tedious) is: 1. Copy the raw SQL from the XML mapper. 2. Manually scrub the XML tags like <if test="..."> and <where>. 3. Replace all #{param} placeholders with actual values, one by one. (or :param) 4. Finally, paste the cleaned-up SQL into the IDE’s database console to see if it even runs.
I was surprised to find that, despite many MyBatis plugins existing, none of them seem to offer a "direct execution with parameters" feature within the IDE. I expected this to be a standard feature by now, but it feels like we’re still stuck with manual labor for query verification.
To solve this, I’m building an IntelliJ plugin () that: - Automatically detects parameters in your SQL (XML or Annotations). - Prompts for values and evaluates all dynamic tags/OGNL on the fly. - Executes the final native SQL directly via the IDE’s built-in database tools.
I’m curious to hear from the HN community: 1. If I were to release a tool like this, would it be something you’d actually find useful in your daily work? I'm trying to gauge if others share this specific frustration. 2. How do you currently verify your complex MyBatis queries before they hit production? 3. Are there any specific edge cases or reasons why you think this kind of "direct execution" hasn't been widely implemented yet?
I'm eager to hear your thoughts and suggestions. Many thanks for your feedback!
Discussion (0 Comments)
No comments available or they could not be loaded.