Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Needs Hibernate 5.2.11.Final
- */
- public List<ObjectNode> getQuery(
- Integer anno,
- Integer settimana) {
- Query q = em.createNativeQuery(
- "NATIVE SQL....",Tuple.class);
- List<Tuple> results = q.getResultList();
- List<ObjectNode> json = _toJson(results);
- return json;
- }
- private List<ObjectNode> _toJson(List<Tuple> results) {
- List<ObjectNode> json = new ArrayList<ObjectNode>();
- ObjectMapper mapper = new ObjectMapper();
- for (Tuple t : results)
- {
- List<TupleElement<?>> cols = t.getElements();
- ObjectNode one = mapper.createObjectNode();
- for (TupleElement col : cols)
- {
- one.put(col.getAlias(), t.get(col.getAlias()).toString());
- }
- json.add(one);
- }
- return json;
- }
Add Comment
Please, Sign In to add comment