3 Replies Latest reply on Jan 9, 2014 11:26 AM by kentchov

    is join two entities in audit query possible?

    swetha.dts

      Hi

       

      Am using Envers version : 3.6.3.Final

      I wanted to join two audit tables having a one to many relationship, with criteria's to be passed on both the tables.

       

      For eg: Event.java

       

      @OneToMany(mappedBy = "event", fetch = FetchType.LAZY, orphanRemoval = true)

          @Cascade(value = { CascadeType.ALL })

          private List<Agreement>     agreements          = new ArrayList<Agreement>();

       

       

      Agreement.java

       

      @ManyToOne(fetch = FetchType.LAZY)

          @JoinColumn(name = "ID_EVENT")

          private Event             event;

       

      i want to fetch the event by passing an ID and date of the event and also the status of the agreement.And the result should be the latest version on that date.

      How can i join these conditions in the audit query?

      Can i make all these conditions in a single query?

       

      My query is  :

      AuditQuery query = reader.createQuery().forRevisionsOfEntity(Event.java, false, true);

                 query.add(AuditEntity.id().eq(eventId));

                  query.add(AuditEntity.property("updatedDate").le(updatedDate));

                  query.add(AuditEntity.property("status").ne(Status.DELETE));

                  query.add(AuditEntity.property("agreements.status").eq(INVALID));

       

      I have changed here and there and tried but nothing worked.

       

      Please advice on this issue.

       

      Thanks in Advance,

      Swetha

        • 1. Re: is join two entities in audit query possible?
          adamw

          Unfortunately, joins are not supported. You can only specify ids of related entities.

           

          Adam

          • 2. Re: is join two entities in audit query possible?
            swetha.dts

            Thanks for your timely information Adam.

            I have implemenetd the same in a different way with 2 queries.

            • 3. Re: is join two entities in audit query possible?
              kentchov

              I am having some problems joining the entities myself and struggling with a solution and would appreciate any advice.

               

              I have a specific question. Using envers would it not be possible to use AuditQuery on the two different entity types that are related (parent child or one to many) and then insert the result into some sort of temporary or virtual representation of the audited table (not the ENTITY_AUD table but the ENTITY table) and then to do my query on the virtual table using standard hibernate? If this would work, how do I define / use a temp or virtual representation of the audited table?

               

              Thanks.