### Question:
CommonCourtHierarchyUpdater { @Transactional public void updateCommonCourtHierarchy() { String updateDistrictParentSql = " update common_court child set fk_parent_court = parent.id " + " from common_court parent " + " where left(child.code, 6) = left(parent.code, 6) " + " and child.type = 'DISTRICT' "+ " and parent.type = 'REGIONAL' "; String updateRegionalParentSql = "update common_court child set fk_parent_court = parent.id " + " from common_court parent " + " where left(child.code, 4) = left(parent.code, 4) " + " and child.type = 'REGIONAL' " + " and parent.type = 'APPEAL'"; entityManager.createNativeQuery(updateDistrictParentSql).executeUpdate(); entityManager.createNativeQuery(updateRegionalParentSql).executeUpdate(); }  @Transactional void updateCommonCourtHierarchy();  }### Answer:
@Test public void updateHierarchy() { createCourt("15050000", CommonCourtType.APPEAL, "Sąd Apelacyjny 1"); createCourt("15050500", CommonCourtType.REGIONAL, "Sąd Okręgowy 1_1"); createCourt("15050505", CommonCourtType.DISTRICT, "Sąd Rejonowy 1_1_1"); createCourt("15050510", CommonCourtType.DISTRICT, "Sąd Rejonowy 1_1_2"); createCourt("15051000", CommonCourtType.REGIONAL, "Sąd Okręgowy 1_2"); createCourt("15051010", CommonCourtType.DISTRICT, "Sąd Rejonowy 1_2_1"); createCourt("15100000", CommonCourtType.APPEAL, "Sąd Apelacyjny 2"); createCourt("15100500", CommonCourtType.REGIONAL, "Sąd Okręgowy 2_1"); createCourt("15100505", CommonCourtType.DISTRICT, "Sąd Rejonowy 2_1_1"); createCourt("15100510", CommonCourtType.DISTRICT, "Sąd Rejonowy 2_1_2"); createCourt("15101000", CommonCourtType.REGIONAL, "Sąd Okręgowy 2_2"); createCourt("15101010", CommonCourtType.DISTRICT, "Sąd Rejonowy 2_2_1"); CommonCourt court = commonCourtRepository.findOneByCode("15050500"); assertNotNull(court); assertNull(court.getParentCourt()); commonCourtHierarchyUpdater.updateCommonCourtHierarchy(); court = commonCourtRepository.findOneByCode("15050500"); assertNotNull(court); assertNotNull(court.getParentCourt()); CommonCourt parent = commonCourtRepository.findOneByCode("15050000"); assertEquals(parent.getId(), court.getParentCourt().getId()); }