2023-10-08 05:21:35.706 ERROR 6064 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement] with root cause
org.postgresql.util.PSQLException: ์ค๋ฅ: r.recruitid ์นผ๋ผ ์์
Hint: ์๋ง "r.recruit_id" ์นผ๋ผ์ ์ฐธ์กฐํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
Position: 91
nativeQuery = false ํ๋๊น ํด๊ฒฐ
@Transactional ํ๋๊น ํด๊ฒฐ
@Transactional
@Modifying
@Query(value = "update Recruit r set r.position = :position, r.bonus = :bonus, r.detail = :detail, r.technique = :technique where r.recruitId = :id", nativeQuery = false)
public int changeAll(@Param("position") String position,
@Param("bonus") Long bonus,
@Param("detail") String detail,
@Param("technique") String technique,
@Param("id") Long id);
}
@Transactional
public void patchRecruit(Recruit recruit) {
Recruit findedRecruit = recruitRepository.findById(recruit.getRecruitId()).orElseThrow();
recruitRepository.changeAll(recruit.getPosition(),recruit.getBonus(), recruit.getDetail(), recruit.getTechnique(),recruit.getRecruitId());
}
๊ธฐ๋ณธํค ๋งคํ์ ๋ํ ์ดํด
๋งต์คํธ๋ญ์ค ์ฌ์ฉ์ค ์๋ฌ
๋งต์คํธ๋ญํธ ์ฌ์ฉ์ค์ ๊ณ์ ์๋ฌ๊ฐ ๋ฐ์ํ์๋ค.
@Builder
public class RecruitResponseDto {
private Long recruitId;
private String companyName;
private String nation;
private String region;
private String position;
private Long bonus;
private String technique;
}
default List<RecruitResponseDto> recruitListToRecruitResponseDtos(List<Recruit> recruitList){
List<RecruitResponseDto> recruitResponseDtos = new ArrayList<>();
for(Recruit recruit : recruitList){
Company company = recruit.getCompany();
RecruitResponseDto recruitResponseDto = RecruitResponseDto.builder()
.recruitId(recruit.getRecruitId())
.region(company.getRegion())
.bonus(recruit.getBonus())
.nation(company.getNation())
.companyName(company.getName())
.position(recruit.getPosition())
.technique(recruit.getTechnique())
.build();
recruitResponseDtos.add(recruitResponseDto);
}
return recruitResponseDtos;
}
์ด๋ ๊ฒ ๋๋ฆฌ๋๊น ๋ฐ์ํ๋ ์๋ฌ๋ ์์ฒญ ๋ง์๋๋ฐ
@Getter๋ฅผ ์ถ๊ฐํด์ฃผ๋๊น ์ ์๋์ํ๋ค.
์ฟผ๋ฆฌ
@Query("SELECT r FROM Recruit r WHERE " +
"r.position LIKE %:search% OR " +
"CAST(r.bonus AS string) LIKE %:search% OR " +
"r.detail LIKE %:search% OR " +
"r.technique LIKE %:search% OR " +
"r.company.name LIKE %:search% OR " +
"r.company.nation LIKE %:search% OR " +
"r.company.region LIKE %:search% ")
List<Recruit> findRecruitsBySearchString(@Param("search") String search);
}
๋ชจ๋ ๊ฑธ ์กฐํํ๋ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ๋ ค๋ฉด ์ด๋ฐ์์ผ๋ก ํด์ผํ๋ค. queryDSL๊ฐ์ ๊ธฐ์ ์ ์ฉ์์ด ๊ทธ๋ฅ ๋ ๋ค ๋๋ ค๋ฐ์๊ฑฐ๋ค. ์ด๊ฑฐ ๊ทผ๋ฐ ๋ฌธ์ ๊ฐ ์๋ค. ๋ญ๋๋ฉด
{
"recruitId": 14,
"companyName": "์ํฐ๋๋ฉ",
"nation": "ํ๊ตญ",
"region": "์์ธ",
"position": "๋ฐฑ์๋ ์ฃผ๋์ด ๊ฐ๋ฐ์",
"bonus": 1000000,
"technique": "Python"
},
{
"recruitId": 15,
"companyName": "๋ค์ด๋ฒ",
"nation": "ํ๊ตญ",
"region": "ํ๊ต",
"position": "๋ฐฑ์๋ ์ฃผ๋์ด ๊ฐ๋ฐ์",
"bonus": 1000000,
"technique": "Python"
},
{
"recruitId": 16,
"companyName": "์ํฐ๋์ฝ๋ฆฌ์",
"nation": "ํ๊ตญ",
"region": "๋ถ์ฐ",
"position": "๋ฐฑ์๋ ์ฃผ๋์ด ๊ฐ๋ฐ์",
"bonus": 1000000,
"technique": "Python"
},
{
"recruitId": 17,
"companyName": "์นด์นด์ค",
"nation": "ํ๊ตญ",
"region": "ํ๊ต",
"position": "๋ฐฑ์๋ ์ฃผ๋์ด ๊ฐ๋ฐ์",
"bonus": 1500000,
"technique": "Python"
}
]
๋ถ๋ช
์ํฐ๋๋ฅผ ๊ฒ์์ด๋ก ๋ฃ์๋๋ฐ ์นด์นด์ค๊ฐ ๋์๋ฒ๋ฆฌ๋ค..? ๊ทผ๋ฐ ์ด์ ๋ฅผ ์ฐพ์๋ค...ใ
ใ
ใ
"r.detail LIKE %:search% OR " +
์ด๋ถ๋ถ์ด ๋ฌธ์ ์๋ค. detail์ response๋ก ํ์๋์ง์์ง๋ง DB๋ฅผ ํ์ธํด๋ณด๋
์ํฐ๋๋ฉ์์ ๋ฐฑ์๋ ์ฃผ๋์ด ๊ฐ๋ฐ์๋ฅผ ์ฑ์ฉํฉ๋๋ค. ์๊ฒฉ์๊ฑด์.. ์๋ ๊ฒ ์จ์ ธ์๋๊ฒ..! ์ง์์ฃผ๋๊น ์ ์๋์ํ๋ค.
JPQL์์ Long > String ๋ฐ๊พธ๊ธฐ
"CAST(r.bonus AS string) LIKE %:search% OR "
์ด๋ฐ์์ผ๋ก ์ฌ์ฉํ๋ฉด ๋๋ค!
detail ๊ตฌํ์์
๋ฌธ์ ์ ์ด ์๋๋ฐ ์ง๊ธ ํ์ถ๋๋๊ฒ ํ์ฌ ์์ธํ๋ณด๊ธฐ๋ฅผ ๋๋ฅธ ๊ฒ๊น์ง ํ์ฌ๊ฐ ์ฌ๋ฆฐ ๋ค๋ฅธ ์ฑ์ฉ๊ณต๊ณ ์ ํ์ถ๋๋ค ์ด๋ถ๋ถ ๋ฐ๊ฟ์ค์ผํ๋ค.