如何在springboot jpa

时间:2019-07-04 09:29:50

标签: inner-join spring-boot-jpa

我想使用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中,它给了我记录。

1 个答案:

答案 0 :(得分: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)非常容易!