无法在spring数据jpa中的$users = User::where('status', 1);
$users_query = str_replace(array('?'), array('\'%s\''), $users->toSql());
$users_query = vsprintf($query, $users->getBindings());
dump($users_query);
$all_users = $users->get();
中传递命名参数
我的仓库:
@NamedNativeQuery
基础数据库为 @Query(value = "select stat.desc as desc," +
" stat.priority as priority," +
" (case when sum(activeUser) is null then 0 else sum(activeUser) end) as activeUser," +
" (case when sum(totalUser) is null then 0 else sum(totalUser) end) as totalUser" +
" from lookup.user stat left outer join" +
" (" +
" select user.role as role, " +
" sum (case when user.STATUS = 'ACTIVE' then 1 else 0 end) as activeUser," +
" count(*) as totalUser," +
" user.group as group" +
" from Ctrl.user user" +
" where user.group =:userGroup " +
" and user.branch_code =:branchCode " +
" group by user.role,user.group" +
" ) as tbl on stat.role = tbl.role and stat.group = tbl.group" +
" where stat.group =:userGroup " +
" group by stat.desc, stat.priority" +
"", nativeQuery = true)
public List<com.cimb.dto.UserStatusSummary> getSummaryReport(@Param(value = "userGroup") String userGroup, @Param(value = "branchCode") String branchCode);
当我尝试访问该方法时,出现以下错误。
DB2
如果我用值对那些命名参数进行硬编码,那么它就起作用了。
我不能使用 DB2 SQL Error: SQLCODE=-302, SQLSTATE=22001, SQLERRMC=null, DRIVER=4.25.13
,因为实际查询中包含一些子查询,因此我不能使用jpql
编辑更新
经过一番挖掘,我发现我传递的参数在子查询中,因为JPQL
没有子查询的概念,因此没有注入命名参数,这会导致语法错误。
现在如何使用JPA
请帮助。
答案 0 :(得分:0)