Getting column names from a JPA Native Query
After a long time without any answer, And based on my own further research, It seems that it can not be possible, Unfortunately.
Getting dynamically generated column names from result of Hibernate native query
Finally, found the solution, and I'm going to share with you(maybe helps someone). Here is what I did:
- I added Spring JDBC Support to my application, then,
- I used Spring SimpleJdbcTemplate Querying, there is a method:
SimpleJdbcDaoSupport.getSimpleJdbcTemplate().queryForList(nativeQuery)
which returnsList<Map<String,Object>>
Spring - native queries mixed with hibernate when columns name are not the same as in the model
Note: you've duplicated the lastName field in your Entity, however I'll assume that's a typo because the compiler won't have allowed that in your real code.
All of the column & entity names match those in the actual table with the exception of lastName/last_name and id/user_id, so this becomes confusing when one looks at the @Query. The only place you're currently mixing names is the lastName/last_name element of your query, but I suspect it'll also complain when trying to map the result set to the Entity because of the id/user_id problem. (the answer there will be to be explicit about which columns you're retrieving and use a column alias to map user_id to id.)
Basically, the problem is in your question: you're trying to mix native & entity mapped names. You cannot - use one or the other.
Related Topics
How to Use Variables in One Method into Another Method
Redirecting to a Servlet from a Jsp on Button Click
Get Unique Values from Arraylist in Java
How to Skip the First Line of a CSV in Java
Sqlite_Error - SQL Error or Missing Database (Near "Autoincrement": Syntax Error)
Mockito Mock Objects Returns Null
Java.Lang.Noclassdeffounderror: Lorg/Apache/Logging/Log4J/Logger; But the Artifact Exists
Spring Boot - Post Method Not Allowed, But Get Works
Transactionrequiredexception Executing an Update/Delete Query
Hibernate Error Executing Ddl Via Jdbc Statement
Include Comma in a Field Value of CSV (Delimeter as Comma) in Java
How to Set the Timeout for a Jax-Ws Webservice Client
Spring @Requestbody and Enum Value
Spring Data JPA How to Locate Attribute With the Given Name
Spring MVC Web Application: No Default Constructor Found
Splitting Data Inside Quotes and Comma Using Regex
Java Regex to Validate Full Name Allow Only Spaces and Letters