XilongPei / Openparts

MIT License
3 stars 1 forks source link

HQL的字符串中不能有{ #57

Closed XilongPei closed 6 years ago

XilongPei commented 6 years ago

当构造出这样的HQL语句,就抛出异常:

select count(*) from (select id,version,name,login_name from tbl_user where
          id not in (select userId from tbl_user_role where roleId='S{VTPY8Bc5B0d4o5wFBOAI')
          and 1=1
          order by update_date_time desc) as table_alias
--------------------------------------
Caused by: org.hibernate.QueryException: Unmatched braces for alias path [select count(*) from (select id,version,name,login_name from tbl_user where
          id not in (select userId from tbl_user_role where roleId='TaAQ1{w2IBTBQlNbgsXO6U')
          and 1=1
          order by update_date_time desc) as table_alias]
    at org.hibernate.loader.custom.sql.SQLQueryParser.substituteBrackets(SQLQueryParser.java:106)
    at org.hibernate.loader.custom.sql.SQLQueryParser.process(SQLQueryParser.java:81)
    at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:134)
--------------------------------------

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/loader/custom/sql/SQLQueryParser.java

XilongPei commented 6 years ago
   <sql>
      <![CDATA[
      select id,version,name,login_name from tbl_user where
      id not in (select userId from tbl_user_role where roleId=@roleId#)
      and 1=1
      order by update_date_time desc
      ]]>
    </sql>
XilongPei commented 6 years ago

https://forum.hibernate.org/viewtopic.php?f=1&t=1025423&view=previous http://tool.chinaz.com/regex

XilongPei commented 6 years ago

fill the hole of QueryException. limit: concat() more than 2 strings once just suit for MySQL(?) commit: https://github.com/XilongPei/Openparts/commit/03b867331527ee3e093b9cb6189757b57abdceb0