When I use @Query annotation with select fields, I dont get the entity object back. How can I get the entity object back?
public interface CreditCenterRepository extends JpaRepository<CreditCenter, Long> {
@Query("SELECT CC.id, CC.loanId, CC.clientId FROM CreditCenter CC")
List<CreditCenter> findAllIds();
}
When I call this method from my controller, it does not throw any error, but, when I try to iterate it throws classcastexception
List<CreditCenter> objects = findAllIds();
for (CreditCenter cc : objects) { //This line throws ClassCastException
//some logic
}
See Question&Answers more detail:os