[英]Spring JPA repository doesn't return List of entities
I try to get simple List of Rawtype entities with help of findBy method in the myMethod . 我尝试在myMethod中使用findBy方法获取简单的Rawtype实体列表。 But I get nothing - rawtypes doesn't contain any entity.
但我什么都没得到 - rawtypes不包含任何实体。 Although findAll method works fine.
虽然findAll方法工作正常。 Please tell we where is my mistake.
请告诉我们我的错误在哪里。
Rawtype.java 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 RawtypeRepository.java
public interface RawtypeRepository extends JpaRepository<Rawtype, Integer> {
List<Rawtype> findByRtName(String rtName);
}
RawtypeServiceImpl.java 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? 你能尝试打印
findAll()
方法返回的所有实体的rtName
吗? May be there isn't any record with 'RawName' as rtName
. 可能没有“RawName”作为
rtName
任何记录。
Also, you can enable logging
for JPA to see the generated query. 此外,您可以为JPA启用
logging
以查看生成的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.