Scenario: You are lazy and don’t want to create an @Entity class and just want to query a few columns.
@PersistenceContext(unitName="dev") EntityManager entityManager; @SuppressWarnings("unchecked") public List<Object[]> retrieveCustomerInfo(){ try { return entityManager.createNativeQuery("select name, age from Customer").getResultList(); } catch (Exception e) { logger.error("Customer Query Exception", e); } return null; } public void invokeCustomerEndpointWithInfo(List<Object[]> customerInfo){ Iterator<Object[]> it = customerInfo.iterator( ); while (it.hasNext( )) { Object[] result = (Object[])it.next(); String name = (String) result[0]; Integer age = (Integer) result[1]; } }