hibernate: Unable to locate appropriate constructor on class - HQL

Lipo

When I trying to execute this HQL to return an object Ponto I receive this error:

ERROR [org.hibernate.hql.PARSER] (http-localhost-127.0.0.1-8080-2) Unable to locate appropriate constructor on class [br.com.cdv.model.entity.Ponto] [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: br.com.cdv.model.entity.Ponto]

DAO

    @SuppressWarnings("unchecked")
    @Override
    public List<Ponto> listLoja(Integer idLoja) {

        Query q = getSession().createQuery("select new Ponto(0,ss.cliente,ss.loja,null,null,null,null,null,sum(qtdPontos),'',0) "
            + "from Ponto as ss where ss.loja.id = :idLoja "
            + "group by ss.cliente, ss.loja");  

        q.setParameter("idLoja", idLoja);

        return (List<Ponto>) q.list();
    }  

My Entity / Class

@Entity
@Table (name = "ponto")
public class Ponto implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="cliente", nullable=true)
    private UsuarioCliente cliente;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="loja", nullable=false)
    private UsuarioLoja loja;

    @Column(name="dataCriacao")
    private Date dataCriacao;

    @Column(name="dataUtilizado", length=12, nullable=true)
    private Date dataUtilizado;

    @Column(name="dataExpira")
    private Date dataExpira;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "funcionario", nullable=true)
    private Funcionario funcionario;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pontoReceber", nullable=true)
    private PontoReceber pontoReceber;

    @Column(name="qtdPontos", nullable=false)
    private long qtdPontos;

    @Column(name="obsPontos", nullable = true,length=300)
    private String obsPontos;

    @NotEmpty
    @Column(name="tipo",nullable = false)
    private Integer tipo;

    public Ponto(Integer id, UsuarioCliente cliente,UsuarioLoja loja, Date dataCriacao, Date dataUtilizado,
              Date dataExpira, Funcionario funcionario, PontoReceber pontoReceber, long qtdPontos, String obsPontos, Integer tipo) {
        setId(id);
        setCliente(cliente);
        setLoja(loja);
        setDataCriacao(dataCriacao);
        setDataUtilizado(dataUtilizado);
        setDataExpira(dataExpira);
        setFuncionario(funcionario);
        setPontoReceber(pontoReceber);
        setQtdPontos(qtdPontos);
        setObsPontos(obsPontos);
        setTipo(tipo);
    }
        // getters and setters
    }

Control:

@RequestMapping("/listarClientes")
    public String listarClientesPontos(Map<String, Object> map, HttpSession session) {

        ...

        List<Ponto> pontos = pontoService.listLoja(loja.getId());

        map.put("pontos", pontos);

        return "listaClientesPonto";
    }
}

View:

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>


    <body>
        <h2>Lista Clientes</h2>

        <table>
          <tr>
            <th>ID Cliente</th>
            <th>CPF Cliente</th>
            <th>Pontos totais:</th>
          </tr>

          <c:forEach items="${pontos}" var="ponto" varStatus="count">
          <tr>
            <td>${ponto.cliente.id}</td>
            <td>${ponto.cliente.cpf}</td>
            <td>${ponto.qtdPontos}</td>
          </tr>
          </c:forEach>
        </table>
    </body>

Why I am getting this error?
Has any better why to receive this Object Ponto in a List?

obs.. without new Ponto(...) returns a list of Ponto with unidentified Objects[]

Lipo

Found the problem... I made some bad constructors, so I edited the constructors in my entity:

@Entity
@Table (name = "ponto")
public class Ponto implements java.io.Serializable {

    @Id
    @GeneratedValue
    private Integer id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="cliente", nullable=true)
    private UsuarioCliente cliente;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="loja", nullable=false)
    private UsuarioLoja loja;

    @Column(name="dataCriacao")
    private Date dataCriacao;

    @Column(name="dataUtilizado", length=12, nullable=true)
    private Date dataUtilizado;

    @Column(name="dataExpira")
    private Date dataExpira;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "funcionario", nullable=true)
    private Funcionario funcionario;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pontoReceber", nullable=true)
    private PontoReceber pontoReceber;

    @Column(name="qtdPontos", nullable=false)
    private long qtdPontos;

    @Column(name="obsPontos", nullable = true,length=300)
    private String obsPontos;

    @NotEmpty
    @Column(name="tipo",nullable = true)
    private Integer tipo;

    public Ponto() {
    }

    public Ponto(UsuarioCliente cliente, UsuarioLoja loja, long qtdPontos) {
        this.cliente = cliente;
        this.loja = loja;
        this.qtdPontos = qtdPontos;
    }
    // getters and setters
}

and HQL:

    Query q = getSession().createQuery("select new Ponto(ss.cliente,ss.loja,sum(ss.qtdPontos) as qtdPontos) "
            + "from Ponto as ss where ss.loja.id = :idLoja "
            + "group by ss.cliente, ss.loja");
    q.setParameter("idLoja", idLoja);

I am crying like a baby, four days with this issue.

Thanks for the directions Thufir Hawat.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to locate class after new object in select query

From Dev

Unable to create a constructor in C++ class

From Dev

QuerySyntaxException locating appropriate constructor in Hibernate

From Dev

Getting error Could not locate appropriate constructor on class

From Dev

Hibernate: No default constructor for entity Inner Class

From Dev

Hibernate: Unable to load class

From Dev

org.hibernate.TransactionException: Unable to locate JTA UserTransaction

From Dev

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor

From Dev

No appropriate default constructor available

From Dev

Hibernate: Unable to locate persister: java.math.BigDecimal

From Dev

QuerySyntaxException: Unable to locate class

From Dev

Criteria API Unable to locate appropriate constructor on class

From Dev

HQL is unable to understand a class's property which is a set of another class

From Dev

Using JPQL(not HQL) with Hibernate

From Dev

JPA - Unable to locate appropriate constructor on class

From Dev

How to find appropriate PPA for installing specific package to solve Unable to locate package?

From Dev

Configuring Hibernate for HQL

From Dev

org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class

From Dev

hibernate HQL Query select

From Dev

HQL Hibernate many tables

From Dev

Unable to locate the specified class: Hooks.php in codeigniter

From Dev

org.hibernate.TransactionException: Unable to locate JTA UserTransaction

From Dev

Ctor-initializer for a class doesn't call to the appropriate constructor

From Dev

C++ templated class "no appropriate default constructor available"

From Dev

Junit Runner Class Unable to locate Step Definition file

From Dev

HibernateQueryException: Unable to locate class

From Dev

Hibernate: Unable to locate persister: java.math.BigDecimal

From Dev

org.hibernate.HibernateException: Unable to locate current JTA transaction

From Dev

"No appropriate constructor available"

Related Related

  1. 1

    Unable to locate class after new object in select query

  2. 2

    Unable to create a constructor in C++ class

  3. 3

    QuerySyntaxException locating appropriate constructor in Hibernate

  4. 4

    Getting error Could not locate appropriate constructor on class

  5. 5

    Hibernate: No default constructor for entity Inner Class

  6. 6

    Hibernate: Unable to load class

  7. 7

    org.hibernate.TransactionException: Unable to locate JTA UserTransaction

  8. 8

    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor

  9. 9

    No appropriate default constructor available

  10. 10

    Hibernate: Unable to locate persister: java.math.BigDecimal

  11. 11

    QuerySyntaxException: Unable to locate class

  12. 12

    Criteria API Unable to locate appropriate constructor on class

  13. 13

    HQL is unable to understand a class's property which is a set of another class

  14. 14

    Using JPQL(not HQL) with Hibernate

  15. 15

    JPA - Unable to locate appropriate constructor on class

  16. 16

    How to find appropriate PPA for installing specific package to solve Unable to locate package?

  17. 17

    Configuring Hibernate for HQL

  18. 18

    org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class

  19. 19

    hibernate HQL Query select

  20. 20

    HQL Hibernate many tables

  21. 21

    Unable to locate the specified class: Hooks.php in codeigniter

  22. 22

    org.hibernate.TransactionException: Unable to locate JTA UserTransaction

  23. 23

    Ctor-initializer for a class doesn't call to the appropriate constructor

  24. 24

    C++ templated class "no appropriate default constructor available"

  25. 25

    Junit Runner Class Unable to locate Step Definition file

  26. 26

    HibernateQueryException: Unable to locate class

  27. 27

    Hibernate: Unable to locate persister: java.math.BigDecimal

  28. 28

    org.hibernate.HibernateException: Unable to locate current JTA transaction

  29. 29

    "No appropriate constructor available"

HotTag

Archive