How to Solve MyBatisPlus Error: Failed to process, please exclude the tableName or statementId

Error reporting details:
error querying database. Cause: com.baomidou.mybatisplus.core.exceptions.mybatisplus exception: failed to process, please exclude the tablename or statementid. Error SQL: XXXXXXXX 

Error reason:
the user-defined SQL is used, which may contain special functions or complex syntax, so it is not supported by jsqlparser (the fields such as tenant ID cannot be added), so the jsqlparserexception is thrown.

The exception is caught by mybatisplus and is encapsulated as mybatisplus exception and then thrown.

Source code: com.baomidou.mybatisplus.core.parser.abstractjsqlparser

solution:
failed to process, please exclude the tablename or statementid
translation is: processing failed, please exclude the table name or statement ID
the P.S. prompt is very specific, but it’s easy to be confused, because the unfamiliar people don’t know that the tenant ID has a problem

Method 1: exclude the table name
when configuring tenanthandler of mybatisplus, filter out the table in dotablefilter method (that is, do not process the tenant ID field of the table).

Method 2: exclude the statement
mark @ sqlparser (filter = true) on the interface of custom SQL

    @SqlParser(filter = true)
    @Select("SQL")
    void selectDemo();

The official explanation for this note is:

Tenant annotation supports method and mapper interface. The default value is false
true means to filter SQL parsing, that is, it will not enter the isqlparser parsing chain
if it is false, it will enter the parsing chain and append a tenant_ ID and so on.

Similar Posts: