Skip to content

Commit

Permalink
update findByJurisdictionId native query (#1509)
Browse files Browse the repository at this point in the history
Co-authored-by: dinesh1patel <[email protected]>
  • Loading branch information
aktaskaan and dinesh1patel authored Oct 10, 2024
1 parent 7793d9a commit 3ba95ac
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
public interface CaseTypeLiteRepository extends DefinitionRepository<CaseTypeLiteEntity, Integer> {

@Query(value = "SELECT "
+ "ct.id,ct.description,ct.jurisdiction_id,ct.name,ct.reference AS reference,ct.version "
+ "FROM case_type ct "
+ "INNER JOIN jurisdiction j "
+ "ON ct.jurisdiction_id = j.id "
+ "ct.id, ct.description, ct.jurisdiction_id, ct.name, ct.reference AS reference, ct.version "
+ "FROM case_type ct "
+ "INNER JOIN ("
+ "SELECT reference,MAX(version) AS max_version "
+ "FROM case_type "
+ "GROUP BY reference) max_versions "
+ " SELECT ct.reference, MAX(ct.version) AS max_version "
+ " FROM case_type ct "
+ " JOIN jurisdiction j "
+ " ON j.id = ct.jurisdiction_id "
+ " WHERE j.reference = :jurisdictionReference "
+ " GROUP BY ct.reference"
+ ") max_versions "
+ "ON ct.reference = max_versions.reference "
+ "AND ct.version = max_versions.max_version "
+ "WHERE j.reference = :jurisdictionReference", nativeQuery = true)
+ "AND ct.version = max_versions.max_version", nativeQuery = true)
List<CaseTypeLiteEntity> findByJurisdictionId(@Param("jurisdictionReference") String jurisdiction);

@Query("select c from CaseTypeLiteEntity c where c.reference=:caseTypeReference "
Expand Down

0 comments on commit 3ba95ac

Please sign in to comment.