0

我想使用springboot jpa实现下面的查询,有可能吗?

    select * from 
    Claims.misuser.CLXMstApplicationRole AR WITH (NOLOCK) INNER JOIN 
    PADB.misuser.clxmstaccesspermission AP WITH (NOLOCK) ON 
    AP.intApplicationRoleId = AR.intApplicationRoleId 
    where AR.txtApplicationRoleCode = 'CRUAPP'

我在我的存储库界面中编写了以下代码

@Query(value=QueryConstants.InnerJoin_AppRole_AccessPermission)
List<ApplicationRole> findBy_InnerJoin_AppRole_AccessPermission();

QueryConstants.java

 InnerJoin_AppRole_AccessPermission="select AR FROM com.infosys.claims.broadband.springboot.entity.claims.ApplicationRole AR "+
                                                                  "INNER JOIN com.infosys.claims.broadband.springboot.entity.padb.AccessPermission AP"+
                                                                  "ON AR.applicationRole = AP.applicationRoleId" + 
                                                                  "where AR.applicationRoleCode = 'CRUAPP' ";

但这给了我空列表,在 mssql 中,它给了我记录。

4

1 回答 1

0

您可以按原样使用查询。

@Query(value = "select * from 
    Claims.misuser.CLXMstApplicationRole AR WITH (NOLOCK) INNER JOIN 
    PADB.misuser.clxmstaccesspermission AP WITH (NOLOCK) ON 
    AP.intApplicationRoleId = AR.intApplicationRoleId 
    where AR.txtApplicationRoleCode = (?1)", nativeQuery = true)
List<ApplicationRole> findBy_InnerJoin_AppRole_AccessPermission(ApplicationRoleCode crudApp); 

只需将变量的值设置crudApp"CRUAPP".

,nativeQuery = true) 如果您对您的查询有信心,在上面的代码中就很容易了!

于 2019-08-14T10:05:32.020 回答