2017-10-14 63 views
2

有什麼問題?嵌套異常是org.hibernate.HibernateException:無法實例化結果類

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

解決 公共ReportDTO(){}

回答

1

Hibernate對所有的實體有一個默認的無參數的構造函數。
如果你的實體類沒有它,或者如果它不公開,你會得到這個異常。

相關問題