【问题标题】:Does Querydsl not support not()?Querydsl 不支持 not() 吗?
【发布时间】:2020-09-30 19:12:19
【问题描述】:
//update q_top_banner set banned = !banned where id = x;
queryFactory.update(Q_TOP_BANNER)
  .set(Q_TOP_BANNER.banned, Q_TOP_BANNER.banned.not())
  .where(Q_TOP_BANNER.eq(id))
  .execute();

MySQL55方言
com.mysql.cj.jdbc.Driver

java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:不在第 2 行第 24 列附近 [更新 com.gzlh.xiaolian.news.entity.TopBanner topBanner 设置 topBanner.banned = 不是 topBanner.banned

【问题讨论】:

    标签: querydsl


    【解决方案1】:

    QueryDSL 支持它,但 Hibernate 在 DML 查询中不支持它。

    您必须在此处使用! 运算符,而不是NOT。示例:

    queryFactory.update(Q_TOP_BANNER)
      .set(Q_TOP_BANNER.banned, Expressions.booleanTemplate("!{0}', Q_TOP_BANNER.banned))
      .where(Q_TOP_BANNER.eq(id))
      .execute();
    

    【讨论】:

      猜你喜欢
      • 2013-03-29
      • 2022-08-10
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 2016-12-26
      相关资源
      最近更新 更多