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");
}
}
Can you try printing rtName of all the entities returned by findAll() method? May be there isn't any record with 'RawName' as rtName.
Also, you can enable logging for JPA to see the generated query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With