Trying to figure out a solution for a problem I am facing, but cannot find any material online so far to help me.
Essentially what I have is a method in a rest controller that passes a query string to my Hibernate DAO and gets in return data requested.
e.g.
@RequestMapping("/submitQuery")
public Object submitQuery() {
// example of a query string, note this is dynamic and thus never hardcoded
String query = "SELECT C.amount, C.transactionDate, R.amount, R.transactionDate FROM CAR C, RFT R";
return DAO.submitQuery(query);
}
DAO:
public List<T> submitQuery(String query) {
Query q = getSession().createQuery(query);
return q.list();
}
This query string will be dynamic so the option of creating a entity and attaching it against query is not an option.
The above method will return data in following format:
[
[
-4890.38,
1451826000000,
25.04,
1421499600000
],
[
-660,
1413205200000,
25.04,
1421499600000
],
[
-10768.53,
1423054800000,
25.04,
1421499600000
]
]
So no headers and on top of that dates have been converted into digits. What i want to achieve is have the method return the results in following format:
[
[
"amountc" : -4890.38,
"datec" : "01-03-2014",
"amountr" : 25.04,
"dater" : "01-03-2014"
],
[
"amountc" : -660,
"datec" : "03-02-2014",
"amountr" : 25.04,
"dater" : "03-02-2014"
],
[
"amountc" : -10768.53,
"datec" : "01-02-2014",
"amountr" : 25.04,
"dater" : "01-02-2014"
]
]
Any advice/assistance would be appreciated.
NOTE: Cannot use DTOs or Entities as the Query String is dynamic and changes. Query string i have there is just as example.
ammountc,datec,amountr,daterand instead of returningDAO.submitQuery(query)build a DTO list from this list and return it.