in Education by
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)

1 Answer

0 votes
by
If you required only couple of columns the you can use Object[] object array @Query("SELECT u.email, u.password FROM User u WHERE email = :email") Optional getCredentialsByEmail( @Param("email") String email); From 0 position you can get the email From 1 position you can get the password If you like to make it much clear, use Interface public interface Response { public String getEmail(); public String getPAssword(); } Query make sure column names and get names should match, if not you can use allies in query @Query("SELECT u.email, u.password FROM User u WHERE email = :email") Optional getCredentialsByEmail( @Param("email") String email);

Related questions

0 votes
    I am trying to implement the Hateoas using spring boot. In my UserController class i have used the below ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am new to Spring AOP. Using annotation based Spring configuration: @Configuration @EnableAspectJAutoProxy( ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    Which of the following function returns t if the object is a number in LISP? (a) (number ) (b) (numberp ) (c) (numericp ) (d) (numeric ) Please answer the above question....
asked Oct 6, 2022 in Education by JackTerrance
0 votes
    Which of the following function returns t if the object is a number in LISP? (a) (number ) (b) (numberp ) (c) (numericp ) (d) (numeric ) Please answer the above question....
asked Oct 2, 2022 in Education by JackTerrance
0 votes
    Which of the following function returns t if the object is a number in LISP? (a) (number ) (b) (numberp ) (c) (numericp ) (d) (numeric ) Please answer the above question....
asked Sep 23, 2022 in Education by JackTerrance
0 votes
    I'm trying to test my Category class. I'm using Mockery::mock() method, with 'overload:' prefix ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I'm trying to test my Category class. I'm using Mockery::mock() method, with 'overload:' prefix ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    In my unit test I am calling the following: every { connectivityManager.activeNetworkInfo } returns null but ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Which of the following methods returns proxy object? (a) loadDatabase() (b) getDatabase() (c) load() (d) ... & Miscellaneous of Java Select the correct answer from above options...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    system.time function returns an object of class _______ which contains two useful bits of information. (a) ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    _______________ returns TRUE then X can be termed as a matrix data object. (a) is. matrix(X ) (b) is ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have a class that logs on to a server and retrieves some data. The data is put in a NSMutableArray, ... [heleTeksten componentsSeparatedByString:@"\n"]; NSString *searchFor = @"...
asked Jan 16, 2022 in Education by JackTerrance
0 votes
    Which of these methods of Boolean wrapper returns boolean equivalent of an object. (a) getBool() (b) ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of these methods returns the class of an object? (a) getClass() (b) Class() (c) WhoseClass( ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of the following methods returns proxy object? (a) loadDatabase() (b) getDatabase() (c) load( ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 24, 2021 in Education by JackTerrance
...