9 Replies Latest reply on Mar 25, 2011 9:58 AM by adamw

    Remove a revision entry

    boban_jboss

      Hi,

       

      is it possible to remove a revision entry? The idea behind this is to remove a revision entry if a hold-back time of a revision is expired.

       

      Thanks

        • 1. Remove a revision entry
          adamw

          Sure, just lookup the desired revision entity (it's a normal Hibernate entity), and if you have the on-delete-cascade properly set, if you remove it, all auditd data will be removed as well because of foreign key constraints.

           

          Adam

          • 2. Remove a revision entry
            boban_jboss

            Hi Adam,

             

            thank you for the fast reply, but i have to delete more than one revision entity i need something like delete from ... the problem is i have to delete all revisions of all entries with expired hold-back time ... sometimes it can be more than 10000 entries. To load every revision entity and than delete it is, i think, very slow solution. Is there another way to delete revisions maybe with hql?

            • 3. Remove a revision entry
              adamw

              Use a HQL bulk delete: delete from RevisionEntity e where e.revisionDate <= :date or sth similar.

              Just make sure you have the on delete cascades

               

              Adam

              • 4. Remove a revision entry
                boban_jboss

                Hi Adam,

                 

                the hold-back time is not the RevisionEntity revision date it is stored in the audited tabele e.g. Resource_AUD, now i have to join my RevisionEntity with the audited Resource_AUD table. If i use

                 

                from RevisionEntity re join Resource_AUD ra

                 

                i get an excpetion org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! (I think because the mapping i not described) and join on is not supported by hql. How can i join this 2 tables?

                 

                Tank you in advance

                Boban

                • 5. Remove a revision entry
                  adamw

                  The _AUD entities use the full class name with package in Hibernate. So try adding the package name.

                   

                  Adam

                  • 6. Remove a revision entry
                    boban_jboss

                    Hi Adam,

                     

                    thank you very much for your help. In the meantime i try it also with full class name and now i get a NullPointerException:

                     

                    Caused by: java.lang.NullPointerException

                        at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:396)

                     

                    My hql join

                     

                    from RevisionEntity join com.scanplus.cadn.discoverer.model.FileResourceImpl_AUD fra where fra.expireDate = :expiredDate

                     

                    whats wrong now? Apart from that envers is working very good.

                     

                    Boban

                    • 7. Remove a revision entry
                      adamw

                      No idea, that would need some debugging.

                       

                      Adam

                      • 8. Remove a revision entry
                        boban_jboss

                        Hi,

                         

                        at this point, i think, join is not working becaus hibernate don't create mapping between this two tables although they are referenced. To join this tables, the RevisionEntitiy and a _AUD table you have to do a simple hql select such as

                         

                        select ra, re from org.test.foo.bar.model.ResourceImpl_AUD ra, RevisionEntity re where ra.originalId.REV.id=re.id

                         

                        Adam thank you for help.

                        • 9. Remove a revision entry
                          adamw

                          Hmm it should, but maybe joining entities with two different entity modes doesn't work.

                           

                          But I suppose it's working for you now

                           

                          Adam