在 class 的 DAO 中使用不同的 class

Using a different class in a class's DAO

我正在使用 Hibernate 并且我的个人实体有一个数据访问对象:

public interface PersonDAO extends JpaRepository<Person, String>
{
  Person findById(String id);
  CsFinal findByCsFinal_CsStudentId(String id);
}

我知道我可以制作一个 CsFinal DAO 并只调用 findByCsStudentId,但我想知道我在上面做的事情是否可行。这样做的原因是我不确定是否有必要有一个 DAO,我将在整个 DAO 中只有一个方法。

编辑:运行 当前代码时的异常:

Servlet.service() for servlet [dispatcherServlet] in context with path []
threw exception [Request processing failed; nested exception is     
org.springframework.core.convert.ConverterNotFoundException: No converter 
found capable of converting from type [Person] to type [CsFinal]] with    
root cause


org.springframework.core.convert.ConverterNotFoundException: No converter 
found capable of converting from type [Person] to type [CsFinal]

建议为 CsFinal 使用单独的 Dao,因为当您使用存储库 class 进行查找全部或保存时,将根据 Person [=10] 的主键列进行保存=].因此,如果您想利用保存功能,理想情况下您需要为每个实体创建一个单独的存储库 class。