createNativeQuery(queryString,Tuple.class).getResultList() method is not returning list of Tuple data
See original GitHub issueI am using reactive hibernate (1.0.0.CR7) for my spring webflux project. I am getting the object array data while executing native queries and it is working fine. But I need it as a tuple object. So I passed Tuple.class as a second argument to createNativeQuery method. But it will throw an exception as it cannot cast an object to tuple. I just need the data with column alias name. So I choose tuple instead of object array. Kindly help.
Sample code :
String queryString= "select c.country_name as country_name, c.phone_code as phone_code
from erp_country c"; // MySql query
Mutiny.Query<Tuple> query = session.createNativeQuery(queryString, Tuple.class);
List<Tuple> list = query.getResultList().await().indefinitely();
for (Tuple tuple : list) { // here it will throw an exception as object cannot be cast to class javax.persistence.Tuple
System.out.println(tuple.get("country_name") + "-" + tuple.get("phone_code"));
}
Exception Message:
Ljava.lang.Object; cannot be cast to class javax.persistence.Tuple ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; javax.persistence.Tuple is in unnamed module of loader 'app')
I have another project using JPA- hibernate 5.5. There I can pass the second parameter of createNativeQuery as tuple class instead of giving an entity class. So I thought may be there is a chance to use Tuple in reactive hibernate also. If we use tuple class then we can retrieve the data by using alias name in the query string.
Few Reference :
https://stackoverflow.com/questions/16296853/jpa-result-list-cast-object-to-tuple https://stackoverflow.com/questions/44626609/getting-column-names-from-a-jpa-native-query
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
I had the same exact reaction 😃
Thanks @nivinps
Hah. I did not know (or once knew and forgot) that this worked in plain Hibernate.
But if it does, then it should be pretty easy to make it work in HR.