I have the below query to fetch specific columns of a entity/table from database
@Query("SELECT u.email, u.password FROM User u WHERE email = :email")
Optional getCredentialsByEmail( @Param("email") String email);
But this gives the ClassCastException, and that's because the query return the Object type instead of User.
Whereas, if I select all the columns as below:
@Query("SELECT u FROM User u WHERE email = :email")
Optional getCredentialsByEmail( @Param("email") String email);
the query return the correct class type i.e User. I don't understand why this difference is provided by the Spring framework.
Any suggestions please.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)