The following example shows accessing individual properties of entity as list.
Each row with matching condition will be returned as a list.
Refer first example for the configuration and mapping.
String HQL_QUERY = "select new list(comp.id, comp.name) from Company comp where comp.employeeCount >= 23430";
List<?> rows = session.createQuery(HQL_QUERY).list();
while (rowsIt.hasNext()) {
row = (List<?>) rowsIt.next();
System.out.println(row + "--> Company Id : " + row.get(0) + " Company Name : " + row.get(1));
}
Selected row count : 6
[2, ABC]--> Company Id : 2 Company Name : ABC
[3, MNO]--> Company Id : 3 Company Name : MNO
[4, IJK]--> Company Id : 4 Company Name : IJK
[5, ART]--> Company Id : 5 Company Name : ART
[6, RNK]--> Company Id : 6 Company Name : RNK
[7, AOQ]--> Company Id : 7 Company Name : AOQ