0

I'm works with JPA and I'm doing query SQL but I don't know how to convert to namedQuery this is the query with sql:

SELECT DISTINCT o.descripcion, 
            t.descripcion ,
            d.descripcion ,
            e.numRegistrosReportados 
FROM estadisticoRD e, oficina o, tipoOficina  t, depto d 
WHERE e.anual = 2013 AND e.mes=9 AND 
   e.codOficina='A1B'  AND
   e.codOficina = o.codOficina AND
   o.depto = d.codDepto 
GROUP BY d.descripcion, t.descripcion, o.descripcion

But when I try to do the named query I have got problem, this is the attemp of namedquery:

@NamedQuery(name = "EstadisticoRD.findByEstadistico",
        query = "SELECT e FROM EstadisticoRD e,Oficina o, TipoOficina t, Depto d WHERE e.anual=:ANUAL AND e.mes=:MES AND e.codOficina=:CODOFICINA AND e.codOficina=o.codOficina")

But when I try to match the value of a entity withe the value with other entity I get a warning The left and right expressions type must be of the same type

exactly in this part of the named query: e.codOficina=o.codOficina

Obviously isn't the olny trouble because I don't know how to get a multples values from differents entities.

This is the entity:

public class EstadisticoRD implements Serializable
{
   private static final long serialVersionUID = 1L;
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   @Basic(optional = false)
   @Column(name = "id", nullable = false)
   private Long id;
   @Column(name = "anual", length = 4)
   private String anual;
   @Column(name = "mes", length = 2)
   private String mes;
   @Column(name = "numRegistrosReportados")
   private BigInteger numRegistrosReportados;

   @ManyToOne
   private Oficina codOficina;
   @ManyToOne
   private Depto depto;

   public EstadisticoRD() {
   }
}

How I do to match values the differents entities?

How I do to get multiples values from named query?

Thank you for your answers.

Cristian
  • 1,480
  • 5
  • 32
  • 65

1 Answers1

0

hi Cristian Chaparro A. You have a problem in the join part of your query. In the JPA you can't use your structure(You can but it is not so simple as join :)). For more information look here Your query will be looks like :

SELECT e FROM EstadisticoRD e inner join e.codOficina as o inner join e.depto as d ...
koropatva
  • 11
  • 2
  • Sorry, but I believe that I don't understand, because I tried to did the test some like : `SELECT e from EstadisticoRD e JOIN e.codOficina o WHERE e.codOficina = o.codOficina` and I get the same problem. – Cristian Nov 19 '13 at 21:01
  • Problem can be in the JoinColumn. Can you show Oficina class? I see that you don't have, it in the EstadisticoRD entity. ManyToOne private Oficina codOficina; – koropatva Nov 20 '13 at 13:52