简体   繁体   English

具有多重实体的NamedQuery并获取多重属性

[英]NamedQuery with multiples entities and get multiples attributes

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: 我正在使用JPA,正在执行查询SQL,但是我不知道如何转换为namedQuery,这是使用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的尝试:

@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 但是,当我尝试将某个实体的值与其他实体的值进行匹配时,我会收到一条警告The left and right expressions type must be of the same type

exactly in this part of the named query: e.codOficina=o.codOficina 恰好在命名查询的这一部分中: 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. 谢谢您的回答。

hi Cristian Chaparro A. You have a problem in the join part of your query. 嗨,克里斯蒂安·查帕罗(Cristian Chaparro A)。您的查询的联接部分有问题。 In the JPA you can't use your structure(You can but it is not so simple as join :)). 在JPA中,您不能使用您的结构(您可以使用,但它不像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 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM