mirror of
https://github.com/iflytek/skillhub.git
synced 2026-10-09 03:17:52 +00:00
fix(infra): add @Transactional to incrementDownloadCount
The @Modifying query requires a transaction context to execute. Adding @Transactional at the repository method level ensures the update query runs within a transaction, even when called from async event listeners. This fixes the issue where download counts were not being incremented after skill downloads due to TransactionRequiredException.
This commit is contained in:
parent
56e7baed15
commit
871278d43a
1 changed files with 2 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ import org.springframework.data.jpa.repository.Modifying;
|
|||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
|
@ -29,6 +30,7 @@ public interface SkillJpaRepository extends JpaRepository<Skill, Long>, SkillRep
|
|||
List<Skill> findByOwnerId(String ownerId);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("UPDATE Skill s SET s.downloadCount = s.downloadCount + 1 WHERE s.id = :skillId")
|
||||
void incrementDownloadCount(@Param("skillId") Long skillId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue