SQL查询:
5.2之后的版本:
NativeQuery<Order> sqlQuery = session.createNativeQuery("select * from t_order", Order.class); List<Order> list = sqlQuery.list();
for(Order order : list) { System.out.println(order); }
5.2之前的版本:
SQLQuery sqlQuery = session.createSQLQuery("select * from t_order"); sqlQuery.addEntity(Order.class);
List<Order> list = sqlQuery.list();
5.1之前的版本:
SQLQuery sqlQuery = session.createSQLQuery("select * from t_order"); List<Object[]> list = sqlQuery.list();
for(Object[] order : list) { for(Object column : order) {
System.out.print(column); System.out.print(" "); } System.out.println(); }