Spring JPA 存储库没有 return 实体列表

Spring JPA repository doesn't return List of entities

我尝试借助 myMethod 中的 findBy 方法获取简单的 Rawtype 实体列表。但我什么也没得到 - rawtypes 不包含任何实体。虽然 findAll 方法工作正常。请告诉我们我的错误在哪里。

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");
    }
}

您可以尝试打印 rtName 方法返回的所有实体吗?可能没有 'RawName' 作为 rtName.

的任何记录

此外,您可以为 JPA 启用 logging 以查看生成的查询。