0 Replies Latest reply on Jul 27, 2010 5:04 PM by guilhermehott

    Filter by entities wich have Associations OneToMany

    guilhermehott

      Hello,

       

      i tried make a search filtering by entities attributtes wich have association OneToMany, but the AuditQuery doesn't find the association.

      I don't know if the envers API recognize the association and i also tried use the @AuditMappedBy and @AuditJoinTable e doesn't works. =/

       

      see the code bellow

       

      Dao

       

      AuditQuery query = AuditReaderFactory.get(this.getSession().getSession(EntityMode.POJO)).createQuery()
                      .forRevisionsOfEntity(Ocorrencia.class, false, true);
              // TODO: implementar os filtros
              if (StringUtils.isNotBlank(nuOcorrencia)) {
                  query.add(AuditEntity.property("numeroOcorrencia").like(nuOcorrencia, MatchMode.ANYWHERE));
              }
              if (aeronave != null) {
                  query.addProjection(new AuditProperty<Aeronave>(new EntityPropertyName("aeronaves")));
                  if (aeronave.getTipoMatricula() != null) {
                      query.add(AuditEntity.property("aeronaves.tipoMatricula").eq(aeronave.getTipoMatricula()));
                  }
                  if (aeronave.getPrefixoMatricula() != null) {
                      query.add(AuditEntity.property("aeronaves.prefixoMatricula").eq(aeronave.getPrefixoMatricula()));
                  }
                  if (StringUtils.isNotBlank(aeronave.getSufixoMatricula())) {
                      query.add(AuditEntity.property("aeronaves.sufixoMatricula").like(aeronave.getSufixoMatricula(),
                              MatchMode.ANYWHERE));
                  }
              }
              if (timestamp != null) {
                  query.add(AuditEntity.revisionProperty("timestamp").ge(timestamp));
              }
              if (count) {
                  query.addProjection(new AuditProperty<Ocorrencia>(new OriginalIdPropertyName("id")).count());
              } else {
                  query.addOrder(AuditEntity.revisionProperty("timestamp").asc());
              }
              return query;
      
      

       

      Entity principal

       

           @OneToMany(mappedBy = "ocorrencia", fetch = FetchType.EAGER)
          @Cascade(CascadeType.ALL)
          @OrderBy("id")
          @Audited(targetAuditMode = RelationTargetAuditMode.AUDITED)
          @AuditMappedBy(mappedBy = "ocorrencia")
          private List<Aeronave> aeronaves = new LinkedList<Aeronave>();
      
      

       

      Entity secondary


      @ManyToOne
          @JoinColumn(name = "CO_Ocorrencia", nullable = true)
          @AuditJoinTable(name = "CO_Ocorrencia")
          private Ocorrencia ocorrencia;
      
      

       

      StrackTrace snippet

       

       

      17:57:52,507 WARN  [OcorrenciaService] could not resolve property: aeronaves of: HIST_br.mil.aer.cenipa.sigipaer.entity.Ocorrencia [select e.aeronaves, count(e.originalId.id) from HIST_br.mil.aer.cenipa.sigipaer.entity.Ocorrencia e, br.mil.aer.cenipa.sigipaer.util.HistoricoRevisionEntity r where e.numeroOcorrencia  like  :_p0 and e.aeronaves.tipoMatricula = :_p1 and e.aeronaves.prefixoMatricula = :_p2 and e.aeronaves.sufixoMatricula  like  :_p3 and e.originalId.REV.id = r.id]
      17:57:52,507 SEVERE [application] java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
      javax.faces.el.EvaluationException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
          at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
          at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
          at javax.faces.component.UICommand.broadcast(UICommand.java:387)
          at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
      
      

       

      Regards.