我尝试借助 myMethod 中的 findBy 方法获取简单的 Rawtype 实体列表。但我什么也没得到 - rawtypes 不包含任何实体。虽然 findAll 方法工作正常。请告诉我们我的错误在哪里。
原始类型.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
原始类型库.java
public interface RawtypeRepository extends JpaRepository<Rawtype, Integer> {
List<Rawtype> findByRtName(String rtName);
}
原始类型ServiceImpl.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");
}
}
最佳答案
你能尝试打印 findAll()
方法返回的所有实体的 rtName
吗?可能没有任何以“RawName”作为 rtName
的记录。
此外,您可以为 JPA 启用日志记录
以查看生成的查询。
关于java - Spring JPA 存储库不返回实体列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35976718/