I have a class which tries to get a record from the db . I see that the Query in the repository is annotated with @Transactional(readOnly = true) When I try to do personRepository.findPersonWithName(); I get 0 records but get a record when I use findByOccupationName. Note that when I run the query on the db I do records with the given person name and When I remove the @Transactional(readOnly = true) the query returns records . Can someone pls help me understand why this is happening ?
@Component
@RequiredArgsConstructor
public class Person {
@Autowired private Ops op;
private final PersonRepository personRepository;
@SneakyThrows
public Object doTest() {
personRepository.findPersonWithName();
}
}
@Repository
public interface PersonRepository {
@Transactional(readOnly = true)
@Query(
value = "SELECT e from #{#entityName} e where e.name = ?1 )
Optional<Object> findPersonWithName(String name);
@Query("SELECT e from #{#entityName} e where e.Occupation = ?1)
Optional<DataSourceEntity> findByOccupationName(String occupationName);
}