2 ms·
Java's JPA interface, of which Hibernate is an implementation, makes it pretty simple. Straight from the documentation of EclipseLink (another implementation):
by twic 12y ago
Java's JPA interface, of which Hibernate is an implementation, makes it pretty simple. Straight from the documentation of EclipseLink (another implementation):
// query for a primitive
Query query = em.createNativeQuery("SELECT SYSDATE FROM DUAL");
Date result = (Date)query.getSingleResult();
// query for a pair of primitives (bletcherous, but not disastrous)
Query query = em.createNativeQuery("SELECT MAX(SALARY), MIN(SALARY) FROM EMPLOYEE");
List<Object[]> results = query.getResultList();
int max = results.get(0)[0];
int min = results.get(0)[1];
// query for a mapped object
Query query = em.createNativeQuery("SELECT * FROM EMPLOYEE", Employee.class);
List<Employee> result = query.getResultList();