2

what is wrong ?

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: Could not instantiate resultclass: ReportDTO; nested exception is org.hibernate.HibernateException: Could not instantiate resultclass: ReportDTO

solve public ReportDTO() {}

1 Answer 1

2

Hibernate requires all entities to have a default no args constructor.
If your entity class doesn't have it, or if it's not public, you'll get this exception.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.