query.list();
Returns the query results as a List. If the query contains multiple results per row, the results are returned in an instance of Object[].
source: http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Query.html#list()
So, we need to modify our code in following way to get the intended result:
List<Object[]> list=query.list();
for(i=0;i<list.size();i++){
Object obj[]=list.get(i);
for(Object obj1:obj){
//set your beans by using appropriate setters
}
}
Other alternative:
Please use ResultTransformer in hibernate to map the resultset(of a complex select query) to a single entity class.
ProdEntity prod = (ProdEntity)session.createQuery("select e.productId as pId,e.price as pPrice from Product e where e.productId = :productId").setParameter("productId", 103).setResultTransformer(Transformers.aliasToBean(ProdEntity.class)).uniqueResult();