selecting multiple expressions using object array

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

We have seen two ways previously and the last way is selecting multiple expressions using object array. It is quite similar to generating reports using JPQL.

Multiple expressions using object array:

Consider we want to select first name and last name of Teacher entity. The criteria can be built as follows.

multiple selection using object array only differs from multiselect while declaring CriteriaQuery and the result type. Criteria query is of type Object[] in this case and same for List<Object[]>
After retrieving results, the object array is simply iterated using enhanced for loop and individual result is printed on the console. This gives the result as follows.

First name = Prasad Last Name = Kharkar
First name = Sushsant Last Name = Pangarkar
First name = Pranil Last Name = Gilda

I hope this example helped understand how selecting multiple expressions using object array works.

References for further study :

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

One thought on “selecting multiple expressions using object array

Leave a Reply

Your email address will not be published. Required fields are marked *