[JPA] UPSERT 방법 (없으면 Insert , 있으면 Update)
목적 JPA를 사용하여 테이블에 특정 조건의 데이터가 없으면 Insert , 있으면 Update 하는 방법 단계 1. 있는 지 없는 지 검색하는 쿼리 사용 2. 데이터 있는 경우(Insert) 검색된 entity에 Key를 포함한 전체 데이터를 Set 한다. 3. 데이터 없는 경우(Update) 검색된 entity에 Key를 제외한 데이터를 Set 한다. (Key를 제외한 데이터만 Update하면 된다) 4. jpa의 save 실행 코드 설명 AdStatistics adStatistics = new AdStatistics(); adStatistics = adStatisticsRepository.findByColdateAndColhour(coldate, colhour); if(adStatistics != ..