Reputation: 45
cq.multiselect(selected_columns);
cq.where(final_selection);
List<Object[]> result = em.createQuery(cq).getResultList();
List<Map<String,Object>> final_result = new ArrayList<>();
for(int i = 0 ; i < result.size() ; i++)
{
Map<String,Object> temp = new HashMap<>();
for(int j = 0 ; j < result.get(i).length ; j++)
temp.put("student_"+selected.get(j), result.get(i)[j]);
final_result.add(temp);
}
when length of Object array inside of result list is 1 then this result.get(i).length generates this error java.lang.ClassCastException: java.lang.Integer cannot be cast to [Ljava.lang.Object
selected columns list consist of column names which I need to select. can anyone help me with this? Thanks in advance.
Upvotes: 0
Views: 357
Reputation: 53694
when you select a single item, you just get that item. it is not embedded within an array of size 1.
Upvotes: 0