org.hibernate.QueryException: could not resolve property: Order of: Classes.Customer

0

I'm having trouble setting up a HQL query in Hibernate, look at the error that occurs:

  

Exception in thread "AWT-EventQueue-0" org.hibernate.QueryException: could not resolve property: Order of: Classes.Customer [select c from Classes.Customer c inner join c.Please Order]

The query I did in MySQL is this but in Hibernate it is giving error:

select cliente.Nome,pedido.Tipo_Servico from cliente join pedido;

Any help I appreciate

Query Screen

  SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

  Session session = sessionFactory.openSession();

   List tabela = session.createQuery("select c from Cliente c inner join c.Pedido as Pedido").list();
   for (Iterator iterator = tabela.iterator(); iterator.hasNext();){
   Cliente clien = (Cliente) iterator.next(); 
  Pedido ped = (Pedido) iterator.next(); 
   DefaultTableModel model = (DefaultTableModel) TBL_Orcamento.getModel();
   model.addRow(new Object[]{


   clien.getNome(),
   ped.getTipo_Servico(),

     });

    }

XML Client Mapping

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
 <class name="Classes.Cliente" table="cliente" >
  <id name="ID_Cliente" column="ID_Cliente">
      <generator class="native"/>
  </id>
     <property name="Nome" type="string" length ="50" column="Nome" />

  </class>
</hibernate-mapping>

XML Order Mapping

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
 <class name="Classes.Pedido" table="pedido">
  <id name="ID_Pedido" column="ID_Pedido">
      <generator class="native"/>
  </id>    
      <property name="Tipo_Servico" type="string" length ="50" column="Tipo_Servico"/>
      <one-to-one name="clienteID_Cliente" cascade="all"/>
   </class>
</hibernate-mapping>

Client Class

package Classes;


public class Cliente {

    private Integer ID_Cliente;
    private String Nome;


    public Cliente(){

    }

    public Cliente(Integer ID_Cliente){
    this.ID_Cliente=ID_Cliente; 

    }


    public String getNome() {
        return Nome;
    }

    public void setNome(String Nome) {
        this.Nome = Nome;
    }

    public Integer getID_Cliente() {
        return ID_Cliente;
    }

    public void setID_Cliente(Integer ID_Cliente) {
        this.ID_Cliente = ID_Cliente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (ID_Cliente != null ? ID_Cliente.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cliente)) {
            return false;
        }
        Cliente other = (Cliente) object;
        return !((this.ID_Cliente == null && other.ID_Cliente != null) || (this.ID_Cliente != null && !this.ID_Cliente.equals(other.ID_Cliente)));
    }



    @Override
    public String toString() {
        return "Classes.Cliente{" + "ID_Cliente=" + ID_Cliente + '}';
    }



}

Order Class

package Classes;


public class Pedido {
    private Integer ID_Pedido;
    private String Tipo_Servico;
    private Cliente clienteID_Cliente;



    public Pedido() {

    }

    public Pedido(Integer ID_Pedido) {
        this.ID_Pedido = ID_Pedido;
    }

      public Integer getID_Pedido() {
        return ID_Pedido;
    }

    public void setID_Pedido(Integer ID_Pedido) {
        this.ID_Pedido = ID_Pedido;
    }

    public String getTipo_Servico() {
        return Tipo_Servico;
    }

    public Cliente getClienteID_Cliente() {
        return clienteID_Cliente;
    }

    public void setClienteID_Cliente(Cliente clienteID_Cliente) {
        this.clienteID_Cliente = clienteID_Cliente;
    }

    public void setTipo_Servico(String Tipo_Servico) {
        this.Tipo_Servico = Tipo_Servico;
    }

     @Override
    public int hashCode() {
        int hash = 0;
        hash += (ID_Pedido != null ? ID_Pedido.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pedido)) {
            return false;
        }
        Pedido other = (Pedido) object;
        return !((this.ID_Pedido == null && other.ID_Pedido != null) || (this.ID_Pedido != null && !this.ID_Pedido.equals(other.ID_Pedido)));
    }



    @Override
    public String toString() {
        return "Classes.Pedido{" + "ID_Pedido=" + ID_Pedido + '}';
    }



}
    
asked by anonymous 22.02.2017 / 21:44

1 answer

0

Queries made in HQL or JPQL are based on the names of their classes, attributes, and the relationship between them. Based on the relationship expressed in your mapping the query should be done that way.

SELECT p FROM Pedido p JOIN FETCH p.clienteID_Cliente

Query Screen

SessionFactory sessionFactory = HibernateUtil.getSessionFactory();

Session session = sessionFactory.openSession();

List<Pedido> pedidos = session.createQuery("SELECT p FROM Pedido p JOIN FETCH p.clienteID_Cliente", Pedido.class).getResultList();
for (Pedido pedido : pedidos) {
    Cliente cliente = pedido.getClienteID_Cliente();
    DefaultTableModel model = (DefaultTableModel) TBL_Orcamento.getModel();
    model.addRow(new Object[]{
        cliente.getNome(),
        pedido.getTipo_Servico()
    });
}
session.close();

NOTE: Do not use the list() method, it is marked as obsolete. I use the getResultList() method.

    
23.02.2017 / 19:17