【问题标题】:Jpa query and, or usingJpa 查询和,或使用
【发布时间】:2018-02-07 09:28:17
【问题描述】:

我写了一个查询,但是这个查询返回了这个错误。你知道吗?我猜我得到这个错误是因为括号

 @Query("select u from Context u where u.user.id <> :userId and u.publicWatch = 1 and  u.isDeleted = 0 and (u.contextType.id  IN :contextTypeId  or u.status IN :status)")
Page<Context> findFilteredContexts(@Param("userId") Long userId,@Param("contextTypeId") List<Long> contextTypeId,@Param("status") List<String> status, Pageable pageable);

错误:

引起:java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException:意外的 AST 节点: {vector} [select count(u) from com.huawei.ti.ei.web.domain.Context u where u.user.id :userId and u.publicWatch = 1 and u.isDeleted = 0 and (u.contextType.id IN (:contextTypeId_0_) 或 u.status IN :status_0_, :status_1_)]

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    如果您使用的是旧版本的 hibernate,则必须用括号 (:status) 将 IN 参数括起来 (HHH-5126)

    受影响的版本 3.5.1 -3.6 但查看评论有人报告更新版本也...

    【讨论】:

    • 否。是新版本。^u.contextType.id IN :contextTypeId^ 可以正常工作。但是另一个IN 不能正常工作
    猜你喜欢
    • 2017-11-20
    • 2012-05-04
    • 2018-05-29
    • 1970-01-01
    • 2019-07-02
    • 2018-01-13
    • 2015-08-05
    • 2011-03-27
    • 2017-12-22
    相关资源
    最近更新 更多