the problem is the following:
I am trying to make a query to tables with hibernate and sql native, the problem is that hibernate returns a list<Object[]> and I need a List of object of my class, but I can't find how to do it
here is my code:
@Override
public List<ProductDTO> getAllDao() {
Session session = FactoryProduct.getSessionFactory().getCurrentSession();
session.beginTransaction();
String sql= "SELECT id, product, quantity, id_warehouse, sold_quantiy, quantity - sold_quantiy AS total FROM `product` INNER JOIN sale ON id = id_product";
SQLQuery query = session.createSQLQuery(sql);
List<Object[]> rows = query.list();
for(Object[] row : rows){
ProductDTO dto = new ProductDTO();
SaleDTO dto2 = new SaleDTO();
dto.setIdDTO(Integer.parseInt(row[0].toString()));
dto.setProductDTO(row[1].toString());
dto.setQuantityDTO(Integer.parseInt(row[2].toString()));
dto.setId_warehouseDTO(Integer.parseInt(row[3].toString()));
dto2.setSold_quantity(Integer.parseInt(row[4].toString()));
dto.setSaleDTO(dto2);
System.out.println(dto);
}
List<Object[]> rows= List<ProductDTO> listDTO;// I need to cast this list object into list productDTO
session.getTransaction();
session.close();
return listDTO;
}