diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-07-26 15:16:26 +1000 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-07-26 15:16:26 +1000 |
| commit | e11138e2b39e07537d836d9a51e3926a78c8b870 (patch) | |
| tree | 215e27a9206bc10fbeb5db4b73f8e92acc4fbf84 /src/main/java/com/stileeducation/markr/service/StudentService.java | |
| parent | 3ac208066db6d11e1a8cc1f6174c6d86b5ac603b (diff) | |
| parent | b59d2f0c722d2e21194ed8d66a17be8128ba7b39 (diff) | |
Merge branch 'caching-issue'
Diffstat (limited to 'src/main/java/com/stileeducation/markr/service/StudentService.java')
| -rw-r--r-- | src/main/java/com/stileeducation/markr/service/StudentService.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/main/java/com/stileeducation/markr/service/StudentService.java b/src/main/java/com/stileeducation/markr/service/StudentService.java index 95ce182..e49f06a 100644 --- a/src/main/java/com/stileeducation/markr/service/StudentService.java +++ b/src/main/java/com/stileeducation/markr/service/StudentService.java @@ -2,6 +2,7 @@ package com.stileeducation.markr.service; import com.stileeducation.markr.entity.Student; import com.stileeducation.markr.repository.StudentRepository; +import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; import java.util.Optional; @@ -15,10 +16,15 @@ public class StudentService { this.studentRepository = studentRepository; } + @Transactional public Student findOrCreateStudent(String firstName, String lastName, String studentNumber) { Optional<Student> optionalStudent = studentRepository.findByStudentNumber(studentNumber); if (optionalStudent.isPresent()) { - return optionalStudent.get(); + Student student = optionalStudent.get(); + // Reset transients + student.setCreated(false); + student.setUpdated(false); + return student; } else { Student student = new Student(); student.setFirstName(firstName); |
