<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SongRenShuo</title>
    <description>The latest articles on DEV Community by SongRenShuo (@songrenshuo).</description>
    <link>https://dev.to/songrenshuo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4260300%2F0ba6d7a6-e179-4086-832f-7e7ce8e9a73e.png</url>
      <title>DEV Community: SongRenShuo</title>
      <link>https://dev.to/songrenshuo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/songrenshuo"/>
    <language>en</language>
    <item>
      <title>Why your MyBatis logs show question marks (and how to turn them into runnable SQL)</title>
      <dc:creator>SongRenShuo</dc:creator>
      <pubDate>Tue, 24 Nov 2026 02:12:59 +0000</pubDate>
      <link>https://dev.to/songrenshuo/why-your-mybatis-logs-show-question-marks-and-how-to-turn-them-into-runnable-sql-4b0e</link>
      <guid>https://dev.to/songrenshuo/why-your-mybatis-logs-show-question-marks-and-how-to-turn-them-into-runnable-sql-4b0e</guid>
      <description>&lt;p&gt;When something breaks in production, the first thing I do is pull a SQL statement out of the logs and run it against the database myself.&lt;/p&gt;

&lt;p&gt;What I actually get is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==&amp;gt;  Preparing: SELECT id, username, status FROM user WHERE username = ? AND status = ? AND created_at &amp;gt; ?
==&amp;gt; Parameters: tom(String), 1(Integer), 2026-11-20 10:00:00.0(Timestamp)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three placeholders, three values, and I have to line them up by hand. Add quotes to the string, reformat the timestamp, strip the type annotations. Doing this once is fine. Doing it fifteen times a day is not.&lt;/p&gt;

&lt;p&gt;So I wrote a tool to do it for me. I assumed it would be a weekend of regex. It turned into a description of what MyBatis log parsing actually involves, and I want to write down the six places it goes wrong — partly so I remember, partly because anyone else automating this will hit the same walls.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 1: The parameters line often isn't there at all
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Preparing:&lt;/code&gt; and &lt;code&gt;Parameters:&lt;/code&gt; are two separate log statements at two different levels.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Preparing:&lt;/code&gt; is DEBUG. &lt;code&gt;Parameters:&lt;/code&gt; requires &lt;strong&gt;TRACE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Plenty of projects run at DEBUG for the mapper package, so you see the statement but never the values. No parsing tool can fix this — there is nothing to parse.&lt;/p&gt;

&lt;p&gt;The check is one search: look for &lt;code&gt;Parameters:&lt;/code&gt; in the log. If zero hits, it's a level problem, not a parser problem. Turn the mapper package up to TRACE in &lt;code&gt;logback.xml&lt;/code&gt; or &lt;code&gt;log4j2.xml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There's a variant of this: the level is fine but another library owns the output. Add p6spy, or a log-shipping agent, and the line may be reformatted or dropped before you ever see it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 2: The prefix is not consistent
&lt;/h2&gt;

&lt;p&gt;Depending on the environment, the version, and whatever wrapper is in play:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==&amp;gt;  Preparing: SELECT ...          # standard StdOutImpl
Preparing: SELECT ...               # bare form
==&amp;gt; Preparing: SELECT ...           # single arrow
[MyBatis] Preparing: SELECT ...     # framework prefix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some teams prepend trace ids or tenant ids, which makes the prefix longer still.&lt;/p&gt;

&lt;p&gt;One regex does not cover all of this. The reliable approach is to treat the prefix as optional noise: anchor on &lt;code&gt;Preparing:&lt;/code&gt; and &lt;code&gt;Parameters:&lt;/code&gt; and skip whatever comes before them. Do not try to match &lt;code&gt;==&amp;gt;&lt;/code&gt; specifically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 3: Batches don't line up
&lt;/h2&gt;

&lt;p&gt;Single statements are easy. Batch inserts are not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==&amp;gt;  Preparing: INSERT INTO log (a, b, c) VALUES (?, ?, ?)
==&amp;gt; Parameters: 1(Integer), 2(Integer), 3(Integer)
==&amp;gt; Parameters: 4(Integer), 5(Integer), 6(Integer)
==&amp;gt; Parameters: 7(Integer), 8(Integer), 9(Integer)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One statement, several parameter lines, each line a separate execution. If your parser takes "the last parameters line", you silently lose the first two rows.&lt;/p&gt;

&lt;p&gt;The correct model: consecutive &lt;code&gt;Parameters:&lt;/code&gt; lines belong to the same statement as repeated executions. Render them as one batch operation rather than three unrelated INSERTs, otherwise the reader can't tell what happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 4: Values contain commas and parentheses
&lt;/h2&gt;

&lt;p&gt;This is where a regex-based parser falls apart.&lt;/p&gt;

&lt;p&gt;The parameters line is comma-separated, but values can contain commas:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==&amp;gt; Parameters: 张三,李四(String), 2026-11-20 10:00:00.0(Timestamp)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is one string parameter, not two. Split on comma and it tears in half.&lt;/p&gt;

&lt;p&gt;Parentheses are just as bad: a value containing &lt;code&gt;()&lt;/code&gt; breaks the &lt;code&gt;(Type)&lt;/code&gt; extraction. Quoted strings with escapes break naive regex immediately.&lt;/p&gt;

&lt;p&gt;What worked for me was a small state machine: walk the line character by character, track whether you're inside a string and how deep the parentheses go, and only treat a comma as a separator when depth is 0 and you're outside quotes. It's not clever, but it's an order of magnitude more reliable than regex.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 5: &lt;code&gt;null&lt;/code&gt; and the string "null" look the same
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;==&amp;gt; Parameters: null, null(String), null(Integer)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three different things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;null&lt;/code&gt; — actually null&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null(String)&lt;/code&gt; — the four-character string "null"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;null(Integer)&lt;/code&gt; — shouldn't exist, but if it does, the type info is not trustworthy&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rendering the first as &lt;code&gt;NULL&lt;/code&gt; and the second as &lt;code&gt;'null'&lt;/code&gt; gives completely different results, and neither throws. Silent wrong answers are worse than loud failures.&lt;/p&gt;

&lt;p&gt;The only signal you have is whether a type annotation is present.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 6: Strip the type, but keep the format
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;tom(String)&lt;/code&gt; becomes &lt;code&gt;'tom'&lt;/code&gt; — drop the type, add quotes.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;2026-11-20 10:00:00.0(Timestamp)&lt;/code&gt; cannot just be type-stripped: it's a date and must become &lt;code&gt;'2026-11-20 10:00:00'&lt;/code&gt;. The trailing &lt;code&gt;.0&lt;/code&gt; is Java's fractional-second placeholder; paste it into a client and some dialects reject it outright.&lt;/p&gt;

&lt;p&gt;The same category of problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;true(Boolean)&lt;/code&gt; → &lt;code&gt;1&lt;/code&gt; or &lt;code&gt;TRUE&lt;/code&gt; depending on dialect&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;byte[]&lt;/code&gt; parameters → logged as &lt;code&gt;[B@1a2b3c&lt;/code&gt;, which is unrecoverable&lt;/li&gt;
&lt;li&gt;Large text → truncated to &lt;code&gt;...(truncated)&lt;/code&gt; in the log&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each of these needs explicit handling, or an honest "this one can't be reconstructed" — not a best-guess SQL that happens to be wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two ways around all of this
&lt;/h2&gt;

&lt;p&gt;Every trap above lives on the "reconstruct SQL from log text" path. You can avoid that path entirely:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change the data source.&lt;/strong&gt; Instead of parsing logs, intercept at the JDBC layer. A lightweight Java agent hooks &lt;code&gt;PreparedStatement.execute*&lt;/code&gt; and gets the statement with parameters already bound, plus real timing, affected row count and the exception. No log format issues, no level requirements. The cost is that the application has to actually be running, and you authorize the agent once.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Change where you look.&lt;/strong&gt; Instead of grepping in a terminal, read the SQL inside the IDE. I built an IntelliJ IDEA plugin that parses the console output into runnable SQL, clusters statements with the same shape, highlights slow queries, and jumps back to the source line. Once the app is running, the same plugin shows the JDBC-level capture: real parameters, milliseconds, rows affected, the original exception.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxi2hftwwidpszz44lqx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxi2hftwwidpszz44lqx.gif" alt="Wrapper chain preview: tick a condition on the left, the SQL re-renders on the right" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0h1eh7gxnfnlhky4g2r.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0h1eh7gxnfnlhky4g2r.gif" alt="Runtime capture: real parameters, millisecond timing, target database badge and source location in one list" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The part that matters day to day: the reconstructed SQL runs from inside the IDE. No copy-paste round trip through a database client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Boundaries, stated plainly
&lt;/h2&gt;

&lt;p&gt;This solves "turn what's in the log into something a human can use". It does not solve:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing parameters when the log level is too low (no data is no data)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;byte[]&lt;/code&gt; and truncated values&lt;/li&gt;
&lt;li&gt;Timing or row counts from the console path (the log doesn't contain them)&lt;/li&gt;
&lt;li&gt;Static preview versus actual execution (static constants get inlined; pagination literals get evaluated)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The plugin is free and open source (Apache-2.0), requires IDEA 2024.3+, and is on the JetBrains Marketplace as &lt;strong&gt;MyBatis SQL Visualizer&lt;/strong&gt;. Docs at &lt;a href="https://sql-visualizer.jvtools.cn" rel="noopener noreferrer"&gt;sql-visualizer.jvtools.cn&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;I'm the author of that plugin. All six traps are ones I actually hit while building the parser, not a generic list of "things that might go wrong". If you've written something similar, you've probably met a few of them — I'd be interested in the shapes I haven't seen yet.&lt;/p&gt;

</description>
      <category>java</category>
      <category>jetbrains</category>
      <category>mybatis</category>
    </item>
    <item>
      <title>Stop restarting your app to find out what a MyBatis-Plus Wrapper generates</title>
      <dc:creator>SongRenShuo</dc:creator>
      <pubDate>Mon, 23 Nov 2026 10:35:24 +0000</pubDate>
      <link>https://dev.to/songrenshuo/stop-restarting-your-app-to-find-out-what-a-mybatis-plus-wrapper-generates-17d3</link>
      <guid>https://dev.to/songrenshuo/stop-restarting-your-app-to-find-out-what-a-mybatis-plus-wrapper-generates-17d3</guid>
      <description>&lt;p&gt;Every Java codebase I have worked on that uses MyBatis-Plus has the same small loop in it. You change one condition, and then you need to know what the change actually produced.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;LambdaQueryWrapper&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;qw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Wrappers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lambdaQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;qw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;StringUtils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isNotBlank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsername&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;getUsername&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUsername&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCreatedFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;getCreatedAt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCreatedFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;orderByDesc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;userMapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;selectPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;qw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things are uncertain here, and none of them are visible in the code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;whether the username condition is in the statement at all, since it depends on a runtime value;&lt;/li&gt;
&lt;li&gt;whether the logical-delete column was appended, and where in the WHERE clause;&lt;/li&gt;
&lt;li&gt;what the paging count query looks like next to the LIMIT query.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So you restart the app, send one request, scroll to the console, find &lt;code&gt;Preparing: SELECT ... WHERE username = ?&lt;/code&gt;, then read the &lt;code&gt;Parameters:&lt;/code&gt; line below it and match placeholders to values by position. With three parameters that is fine. With twelve it is a manual diff. Do it fifteen times a day and the edit-run-read loop starts to cost more than the edit.&lt;/p&gt;

&lt;p&gt;The formatting is the easy part. What makes this hard is that the SQL doesn't exist until several layers have run: the Wrapper builder, the ORM's dialect handling, logical-delete injection, paging. By the time you can read the statement, you have already paid for a restart.&lt;/p&gt;

&lt;p&gt;Three approaches show up in practice. They answer different questions rather than competing.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Restore the statement from logs
&lt;/h4&gt;

&lt;p&gt;The oldest one. The app is already printing &lt;code&gt;Preparing:&lt;/code&gt; and &lt;code&gt;Parameters:&lt;/code&gt; lines; a tool joins them into one executable statement. You get exactly the SQL that ran, with the values that ran. It costs you a running app with SQL logging on, and it only works while those two lines keep being printed. Change the log level, hit a framework that logs at DEBUG, or use a driver that formats parameters differently, and the join falls apart. The plugin family around this — MyBatis Log and its free edition, and similar — has been doing that job for years and does it well.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Preview the statement while coding
&lt;/h4&gt;

&lt;p&gt;This one parses your source and renders the statement without starting anything. Boolean first arguments like &lt;code&gt;StringUtils.isNotBlank(...)&lt;/code&gt; become switches you can flip; parameters you type in are bound with their real types; conditions you leave empty stay as &lt;code&gt;?&lt;/code&gt;. All it needs is the IDE. What it cannot do is decide branches by data, know values that only exist at runtime, or show anything the parser cannot prove.&lt;/p&gt;

&lt;p&gt;That distinction is easy to miss. A static preview is a claim about your code, not a measurement of your database. Constants get inlined in the preview while the ORM still binds them as placeholders at execution, so the text can differ from what actually runs even when the semantics match.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Capture at the JDBC layer while the app runs
&lt;/h4&gt;

&lt;p&gt;The third one attaches a small agent to your application's JVM and records what actually crosses the JDBC boundary: real parameters, milliseconds, affected rows, the error if there was one, and the call stack that led there. You get measurements instead of predictions. The tradeoff is that it says nothing about code paths that never executed, and it needs a one-time authorization inside the IDE.&lt;/p&gt;

&lt;p&gt;I use all three, depending on where I am in the loop. Reading a colleague's Wrapper in review: preview. Chasing a slow endpoint: capture. Reconstructing what a production log line meant: restore.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where they meet
&lt;/h4&gt;

&lt;p&gt;Full disclosure: I'm the author of the plugin I describe below, MyBatis SQL Visualizer. I built it because I kept switching between the three modes and wanted one place to do it.&lt;/p&gt;

&lt;p&gt;The static side works from the gutter icon next to the statement, or &lt;code&gt;Alt+Shift+Q&lt;/code&gt;. Dynamic conditions come in as checkboxes, so you can see the difference between "username present" and "username absent" without editing the code twice. Values are typed in per parameter, LIKE patterns get their &lt;code&gt;%&lt;/code&gt;, and anything you leave blank stays a placeholder. Each statement keeps its own named presets, which is the part I use most: the same Wrapper with three different parameter sets is three saved states instead of three edits.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxi2hftwwidpszz44lqx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuxi2hftwwidpszz44lqx.gif" alt="Wrapper preview: conditions as checkboxes, parameters filled in, SQL re-rendered on the right" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It covers more than MyBatis-Plus Wrapper chains: MPJ joins, mapper XML with dynamic tags, annotation SQL, JdbcTemplate strings, iBatis 2.x &lt;code&gt;sqlMap&lt;/code&gt; statements, and statically derivable JPA / Hibernate queries (derived methods, JPQL, Criteria, Specification, HQL) all render through the same panel.&lt;/p&gt;

&lt;p&gt;The runtime side is where the interesting part is. The capture channel works at the JDBC layer rather than parsing console text, so durations and affected rows are measured, not regexed out of a log line. Entries can be filtered to slow queries only, and structurally identical statements are clustered, which is how a loop that queries one table per iteration becomes visible as one row with a count instead of two hundred rows you scroll past.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmdfn6ahn5tee2c0umwnv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmdfn6ahn5tee2c0umwnv.gif" alt="SQL log entry jumping back to the Java line that executed it, with the call stack expanded" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From an entry you can jump to the Java line or the mapper XML, expand the call stack frame by frame, and focus the list by method or by request. The position comes from the captured stack, so there is nothing to configure.&lt;/p&gt;

&lt;p&gt;The third piece is the one that surprised me in practice: once you can read the final SQL, you also want to go back. Select a statement, press &lt;code&gt;Alt+Shift+J&lt;/code&gt;, and it generates a MyBatis-Plus Wrapper chain, choosing the calling class and return type. Joins, &lt;code&gt;GROUP BY&lt;/code&gt;, &lt;code&gt;HAVING&lt;/code&gt;, &lt;code&gt;DISTINCT&lt;/code&gt;, &lt;code&gt;FOR UPDATE&lt;/code&gt; and aggregate expressions are handled; structures that cannot map cleanly are passed through as &lt;code&gt;apply()&lt;/code&gt; with a note explaining why, rather than silently producing something that looks right and is not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5nk1geio3vdj2cjbi9z1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5nk1geio3vdj2cjbi9z1.gif" alt="SQL to Java: generating a Wrapper chain and picking the calling class" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is also an MCP surface: 11 read-only tools registered on IDEA's built-in MCP Server, so an AI client can ask the plugin to render a statement from source, fetch table and column metadata, run an EXPLAIN, or search local SQL history, instead of guessing column names. Tools that generate SQL never execute it, and the EXPLAIN tool validates its input as a read-only query.&lt;/p&gt;

&lt;h4&gt;
  
  
  Installing it
&lt;/h4&gt;

&lt;p&gt;Marketplace: search for MyBatis SQL Visualizer, or use the &lt;a href="https://plugins.jetbrains.com/plugin/33633-mybatis-sql-visualizer" rel="noopener noreferrer"&gt;plugin page&lt;/a&gt;. It is free, Apache-2.0, no ads, no account. The plugin does not send usage data anywhere; static preview, log restoration, code conversion and diagrams run locally.&lt;/p&gt;

&lt;p&gt;Requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IntelliJ IDEA 2024.3 or later.&lt;/li&gt;
&lt;li&gt;Community Edition covers static preview, log capture and SQL-to-Java. Executing a statement and opening EXPLAIN go through IDEA's database console, which needs Ultimate with Database Tools.&lt;/li&gt;
&lt;li&gt;The MCP tools need IDEA 2025.2 or later with a working MCP Server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  What it does not do
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;It is not an APM. No distributed tracing, no dashboards, no aggregation across machines. It watches the JVM you are running locally.&lt;/li&gt;
&lt;li&gt;Kotlin Wrapper chains are not reliably reconstructable today. The plugin does not show a preview icon for them and does not invent SQL when you trigger the action directly; it tells you why.&lt;/li&gt;
&lt;li&gt;A static preview is not a measurement. Runtime branches, database contents and values that cannot be evaluated need your input, and the text can differ from the executed statement in ways that do not change the semantics.&lt;/li&gt;
&lt;li&gt;EXPLAIN coverage is 14 of the 15 supported dialects; GoldenDB has no plan entry yet. Verification depth differs per database and is documented per engine rather than averaged into one claim.&lt;/li&gt;
&lt;li&gt;Restoring UPDATE / DELETE statements does not produce a rollback script out of thin air. The plugin cannot know pre-image values it never saw; it offers to query a snapshot first and fill the result in.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of that is a dealbreaker for your setup, it probably is. The docs say the same thing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Links
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Plugin: &lt;a href="https://plugins.jetbrains.com/plugin/33633-mybatis-sql-visualizer" rel="noopener noreferrer"&gt;https://plugins.jetbrains.com/plugin/33633-mybatis-sql-visualizer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Docs: &lt;a href="https://sql-visualizer.jvtools.cn/en/" rel="noopener noreferrer"&gt;https://sql-visualizer.jvtools.cn/en/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Source: &lt;a href="https://github.com/SongRenShuo/mybatis-plus-sql-visualizer" rel="noopener noreferrer"&gt;https://github.com/SongRenShuo/mybatis-plus-sql-visualizer&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;MCP setup: &lt;a href="https://sql-visualizer.jvtools.cn/features/mcp" rel="noopener noreferrer"&gt;https://sql-visualizer.jvtools.cn/features/mcp&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you try it and something breaks, the issue tracker and the feedback pool are where it gets fixed. The comparison page on the docs site also lists the other plugin families by what they are for, in case a different one fits your workflow better.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(I maintain this plugin. Capability and boundary statements above follow the project documentation.)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mybatis</category>
      <category>java</category>
      <category>sql</category>
      <category>jetbrains</category>
    </item>
  </channel>
</rss>
