4

I'm executing stored procedure with Hibernate native method, this stored procedure creates column names depending on another table Ids. So its columns look like something like this:

| id | ... some other columns ... | name | c_1 | c_2 | c_4 | c_.. |

If I call Query.getResultList() it returns List<Object[]>, and I don't know column names. I have to know column names (and corresponding column index) to continue my further business logic. I also cannot use EntityManager.createNativeQuery(String s, Class aClass) since it is not one POJO class.

Currently I'm getting List<Object[]> without problem, but I need, for example, Map<String,Object[]> column name as a key and column values as an array of Objects.

How can I get all column names with their values?

Jama A.
  • 15,680
  • 10
  • 55
  • 88

2 Answers2

1

Finally, found the solution, and I'm going to share with you(maybe helps someone). Here is what I did:

Jama A.
  • 15,680
  • 10
  • 55
  • 88
0

(This is just an idea, I haven't tested it. And it needs Criteria API.)

If you manage to get the result as List<javax.persistence.Tuple>, you can take one Tuple and call getElements() on it - you'll get a list of TupleElement<?>s on which you can call getAlias(). Presumably this will be the column name. But I'm not 100% sure and it won't work if there are no tuples (results) returned, but I think it's worth a try. See 9.2. Tuple criteria queries.

For this approach, this might help:

Community
  • 1
  • 1
Petr
  • 62,528
  • 13
  • 153
  • 317