I'm getting the results from the database into a List<Map<String, Object>>. The problem the values are not in order, so I thought to cast in a LinkedHashMap, but I get this exception:
javax.ejb.EJBException: java.lang.ClassCastException: class java.util.HashMap cannot be cast to class java.util.LinkedHashMap (java.util.HashMap and java.util.LinkedHashMap are in module java.base of loader 'bootstrap')
The method is this:
protected EntityManager em;
Query q = em.createNativeQuery("select * from City");
NativeQueryImpl nativeQuery = (NativeQueryImpl) q;
nativeQuery.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
List<LinkedHashMap<String, Object>> r = (List<LinkedHashMap<String, Object>>) nativeQuery.getResultList();
r.stream().forEach(System.out::println);
Does anybody knows how can I print results in order?
Create this class and call it instead of:
AliasToEntityMapResultTransformer.INSTANCE