最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to Handle Missing Data in LEFT JOIN for Custom Fallback Message in JPA Query? - Stack Overflow

programmeradmin0浏览0评论

I'm building a Spring Boot application where I need to fetch data from an AuditLog table. This table is connected to several other entities through LEFT JOIN, and one of those entities is PracticeProvider. The challenge I'm facing is that, when there’s no matching record for PracticeProvider (for a particular entityId), thus i am not getting the expected result

@Query(value = "SELECT new com.v3biomed.api.dto.AuditListDTO(" 
                + "CASE WHEN al.entityName = 'PRACTICE' THEN pt.practiceName"
                + "     WHEN al.entityName = 'Practice Provider' THEN "
                + "          CASE WHEN pp.practice.practiceName IS NULL THEN CONCAT('Missing Practice Provider (ID: ', al.entityId, ')')"
                + "               ELSE pp.practice.practiceName END "
                ....
            
                + "FROM AuditLog al " 
                + "LEFT JOIN Practice pt ON pt.practiceId = al.entityId "
                + "LEFT JOIN PracticeProvider pp ON pp.providerId = al.entityId "
                + "WHERE ((:entityNames IS NULL OR al.entityName = :entityNames) "
                + "       OR (:entityNames = 'Practice' AND al.entityName IN ('Practice', 'Product Product', 'Practice Location', 'Practice Provider', 'Practice Executive' , 'PracticeBiller' ))) "
                .....
    )

when i comment the line it will give me the hard deleted query result also

+ "     WHEN al.entityName = 'Practice Provider' THEN "
                + "          CASE WHEN pp.practice.practiceName IS NULL THEN CONCAT('Missing Practice Provider (ID: ', al.entityId, ')')"
                + "               ELSE pp.practice.practiceName END "

Here's the db data of auditlog table

326097  Practice Provider   189 New Practice Provider is created.   CREATE  Successful  0f68467fdc28d94c50805729a501fac2    1   192.168.1.103   2024-11-11 18:42:23     2024-11-11 18:42:23
325172  Practice Provider   188 New Practice Provider is created.   CREATE  Successful  1b8ee0f029f802408b218c597d3b9aa5    1   192.168.1.103   2024-11-11 15:22:38     2024-11-11 15:22:38
311487  Practice Provider   186 New Practice Provider is created.   CREATE  Successful  1d1c76f87a6e49c9c6e6b65fd50d9105    1   103.156.142.234 2024-10-14 17:04:45     2024-10-14 17:04:45

and here is the Practice provider table data

189 156 Tulipp      P   PNPI123412  PTAN1234                        2024-11-11 18:42:22
187 154 Malik       S                               2024-10-14 17:04:44
186 154 Uday        M                               2024-10-14 17:04:44
185 153 Shalin      P   12348962    84621459    MD                  2024-10-11 11:16:02

So how do i modify the query by which i can write UNKOWN DATA in palce of hard deleted practice provider?

发布评论

评论列表(0)

  1. 暂无评论