【问题标题】:Want to pass String to Query Spring data with @query想通过 @query 传递字符串来查询 Spring 数据
【发布时间】:2016-09-20 17:12:10
【问题描述】:

我只想通过 Spring 数据将两个字符串传递给我的查询, 我的查询看起来像:

@Query("select ts.talent from T_LinkTalentSkill ts , where ts.skill || '_'||ts.lnLevel in (a,b) group by 1 having count(*)=2 ")
public List<T_Talent> searchBySkillTalent(@Param("a") String a,@Param("b") String b);

我试图通过 a 和 b 但我得到:查询验证失败

【问题讨论】:

  • where (,) 前面有个逗号
  • 谢谢你我忘了它:p
  • 从什么时候开始有"||"是 JPQL 中的有效运算符?! JPQL 有 CONCAT
  • 当我没有像“in ('1_1','9_1')”这样的参数进行测试时,它工作正常
  • 不仅是||无效,COUNT(*) 也是无效的。如果不相信我,为什么不阅读 JPA 规范? JPQL != SQL

标签: java hibernate jpa spring-data jpql


【解决方案1】:

要将@Query 注释与本机查询一起使用,您需要使用带有true 值的nativeQuery 标志,请检查以下代码:

@Query(value = "select ts.talent from T_LinkTalentSkill ts  where ts.lnLevel in (?1,?2) group by 1 having count(*)=2", nativeQuery = true)
List<T_Talent> searchBySkillTalent(String a,String b);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    相关资源
    最近更新 更多