Mr Man
Mr Man

Reputation: 1588

Using a different class in a class's DAO

I am using Hibernate and have a Data Access Object for my Person Entity:

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

I know I could make a CsFinal DAO and just call findByCsStudentId, but I am wondering if what I am doing above is possible. The reason for doing it is I am not sure it is necessary to have a DAO where I will only have one method in the entire DAO.

Edit: The exception when running the current code:

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]

Upvotes: 1

Views: 67

Answers (1)

ashwinsakthi
ashwinsakthi

Reputation: 1956

The recommendation is to use a separate Dao for CsFinal , because when you do a find all or save using the repository class, the save will be done based on the primary key column of Person JpaRepository<Person, String>. So if you want to leverage the save functionality you would ideally need to go for a separate repository for each entity class.

Upvotes: 1

Related Questions