0

MyBatisGenerator1.3.1を使用してMapper.xmlファイルを作成しました。MyBatisがMapperファイルを解析すると、BuilderExceptionがスローされます。

Exception in thread "main" org.apache.ibatis.builder.BuilderException: Unknown element <#comment> in SQL statement.
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseDynamicTags(XMLStatementBuilder.java:83)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:43)
    at org.apache.ibatis.session.Configuration.parseStatementNodes(Configuration.java:513)
    at org.apache.ibatis.session.Configuration.buildStatementsForNamespace(Configuration.java:502)
    at org.apache.ibatis.session.Configuration.buildStatementsFromId(Configuration.java:467)
    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:391)
    at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:160)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)
    at $Proxy1.selectByExample(Unknown Source)

parseDynamicTagsは<#comment>フィールドを認識していません。解析しているXMLの部分はselectByExampleです。

  <select id="selectByExample" resultMap="BaseResultMap" parameterType="test.model.TblPosStageExample" >
    <!--       WARNING - @mbggenerated  ..  -->
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from tbl_Pos_Stage
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>

MyBatisは最初のコメントとselectステートメントを解析したようです。タイプ#textのノードを解析したばかりですが、#commentがどこから来ているのかわかりません。

生成されたファイルを変更していませんが、これが過去に正しく機能し、突然停止したことに戸惑っています。


編集:Base_column_list

  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Wed Mar 23 08:04:42 EST 2011.
    -->
    SurrogatePK, businessDate, positionId, busAIdCode, {95 columns deleted for brevity}
    marketValueCcy, settledMarketValueCcy
  </sql>

そしてここにexample_where_clauseがあります

<sql id="Example_Where_Clause" >
  <!--
    WARNING - @mbggenerated
    This element is automatically generated by MyBatis Generator, do not modify.
    This element was generated on Wed Mar 23 08:04:42 EST 2011.
  -->
  <where >
    <foreach collection="oredCriteria" item="criteria" separator="or" >
    <if test="criteria.valid" >
      <trim prefix="(" suffix=")" prefixOverrides="and" >
      <foreach collection="criteria.criteria" item="criterion" >
        <choose >
        <when test="criterion.noValue" >
          and ${criterion.condition}
        </when>
        <when test="criterion.singleValue" >
          and ${criterion.condition} #{criterion.value}
        </when>
        <when test="criterion.betweenValue" >
          and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
        </when>
        <when test="criterion.listValue" >
          and ${criterion.condition}
          <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
          #{listItem}
          </foreach>
        </when>
        </choose>
      </foreach>
      </trim>
    </if>
    </foreach>
  </where>
</sql>
4

2 に答える 2

1

この問題の原因を突き止めました。(myBatis の生成プロセスとは関係ありません。)

この問題は、ユーティリティ パッケージを Eclipse ビルド パスに追加したときに発生しました。これには、多くの古いパッケージを含むサード パーティのライブラリが含まれていました。問題のあるパッケージは古い org.apache.xerces.parsers であると思われます。

Eclipse プロジェクトをゼロからビルドし、パッケージとコードを 1 つずつ追加することで、エラーを見つけました。

実行時エラー (SQL ステートメントの不明な要素 <#comment>) は、プロジェクトを追加することで再現でき、ビルド パスからプロジェクトを削除することで排除できます。

于 2011-04-06T18:34:02.990 に答える
1

置き換えることができない非標準の XML パーサーが原因で、同じ問題が発生しています。MyBatisの問題管理に関する問題を開いて、パッチを添付しました。これがすぐに修正されることを願っています。

編集: r5388 で問題が解決されたことが判明しました。

于 2012-07-16T16:18:16.143 に答える