Код: Выделить всё
public interface CategoryRepository extends JpaRepository{
@Transactional
@Query("select c from Category c where name = :name")
Optional findByName(String name);
}
< /code>
Вот тестовый пример: < /p>
@SpringBootTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class CategoryRepositoryTests {
@Autowired
private CategoryRepository categoryRepository;
@Test
@Transactional
public void testCaching(){
categoryRepository.findByName("cat1");
categoryRepository.findByName("cat1");
}
}
Код: Выделить всё
categoryRepository.findByName("cat1");
< /code>
CategoryПодробнее здесь: https://stackoverflow.com/questions/795 ... d-behavior