出了什么问题?
public List < ReportDTO> listProductAll() {
String sql
= "select "
+ "ip.product_name as productName, "
+ "ip.base_price as basePrice, "
+ "iu.username as username "
+ "from tb_buy a "
+ "left join in_product ip on a.id_product = ip.product_id "
+ "left join im_users iu on a.id_user = iu.user_id ";
Query q = identifyServer.getCurrentSession().createSQLQuery(sql)
.addScalar("productName")
.addScalar("basePrice")
.addScalar("username")
.setResultTransformer(Transformers.aliasToBean(ReportDTO.class));
return q.list();
}
public class ReportDTO {
private String productName;
private Double basePrice;
private String username;
public ReportDTO(String productName, Double basePrice, String username) {
this.productName = productName;
this.basePrice = basePrice;
this.username = username;
}
// getter setter
org.springframework.orm.jpa.JpaSystemException:无法实例化resultclass:ReportDTO;嵌套异常是org.hibernate.HibernateException:无法实例化resultclass:ReportDTO
解决 public ReportDTO(){}
答案 0 :(得分:1)
Hibernate要求所有实体都有一个默认的no args构造函数 如果您的实体类没有它,或者它不是公共的,那么您将获得此异常。