Spring JPA repository doesn't return List of entities

Viewed 3412

I try to get simple List of Rawtype entities with help of findBy method in the myMethod. But I get nothing - rawtypes doesn't contain any entity. Although findAll method works fine. Please tell we where is my mistake.

Rawtype.java

@Entity
@Table(name="rawtype")
public class Rawtype implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="rtid", nullable = false)
    @GeneratedValue
    private int rtId;

    @Column(name="rtname", nullable = false)
    private String rtName;

    //getters and setters

RawtypeRepository.java

public interface RawtypeRepository extends JpaRepository<Rawtype, Integer> {
    List<Rawtype> findByRtName(String rtName);
}

RawtypeServiceImpl.java

@Service
@Transactional
public class RawtypeServiceImpl implements RawtypeService {
    @Autowired
    RawtypeRepository rawtypeRepository;

    public List<Rawtype> findAll() {
        return rawtypeRepository.findAll();
    }

    public myMethod(){
        List<Rawtype> rawtypes = rawtypeRepository.findByRtName("RawName");
    }
}
1 Answers
Related