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.