【发布时间】:2017-12-13 15:13:23
【问题描述】:
我正在使用 Hibernate,并且我的 Person 实体有一个数据访问对象:
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]
【问题讨论】:
-
1.在整个 DAO 中只有一种方法很好(即使没有方法,只有来自层次结构的方法)。 2.你为什么不试试呢?
-
@Shadov 对不起,我忘了添加我得到的异常。继续编辑帖子。似乎共识是每个实体都有一个 DAO,不管每个实体有多少方法