I have Hibernate criteria query as follows:
Criteria criteria = session.createCriteria(Test.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("Month"));
projList.add(Projections.property("Year"));
criteria.setProjection(Projections.distinct(projList));
Here I am trying to fetch distinct values using Month and year similar to
select distinct Month, Year from table;
And finally after complete query I am using list() to fetch the criteria as:
criteriaList = criteria.list();
Now I have the criteriaList as Object with two column data Month and Year. I want to list the results of the query in criteriaList with only Month into a List<Integer>.
I have tried looping through the criteriaList and converting the fetched Object to List<Integer>, but it didn't work. How can I get only first column (Month) from the returned two columns?
Note: Setting projections to only one column (Month) will not help as I need distinct on both Month and Year
Update:
I have used the following types:
List<Object[]> criteriaList = Collections.emptyList();
List<Integer> Month = Collections.emptyList();
And since the number of months returned would be varying, I would like to add the fetched Months into a List<Integer> to perform further operations on.