4 Replies Latest reply on Dec 12, 2010 3:12 AM by vipavel

    AuditEntity.property ClassCastException

    vipavel

      Hi!

       

      I have a problem finding all the revisions for the given entity.

      FIrst, I needed to find all the revisions by the entity id and it worked fine using the following:

       

       

      reader.createQuery().forRevisionsOfEntity(Class.forName(className),
      false, false).add(AuditEntity.id().eq(id)).add(
      AuditEntity.revisionProperty("name").ne("")).add(AuditEntity.revisionProperty("versionType").eq(versionType.getName())).getResultList();

      reader.createQuery().forRevisionsOfEntity(Class.forName(className), false, false)

           .add(AuditEntity.id().eq(id))

           .add(AuditEntity.revisionProperty("name").ne(""))

           .add(AuditEntity.revisionProperty("versionType").eq(versionType.getName()))

           .getResultList();

       

       

      Than, the requirement was changed and the parameter used is the field "originalId". I've changed the code as shown:

       

       

      reader.createQuery().forRevisionsOfEntity(Class.forName(className), false, false)

           .add(AuditEntity.property("originalId").eq(id)) //Long id

           .add(AuditEntity.revisionProperty("name").ne(""))

           .add(AuditEntity.revisionProperty("versionType").eq(versionType.getName()))

           .getResultList();

       

      But now the ClassCastException is thrown

      java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Map

       

      Long - type of id

       

      Any suggestions?

       

      Thank you

      Pavel

        • 1. Re: AuditEntity.property ClassCastException
          adamw

          AuditEntity.id() should work fine - doesn't it? It is equivalent to "originalId.id". So if you must use the second approach, try writing "originalId.id". "originalId" by itself is a composite key containing the entity id and the revision number.

           

          Adam

          • 2. Re: AuditEntity.property ClassCastException
            vipavel

            AuditEntity.id() works. But the "originalId" is a member of my entity. I would like to search for the revisions of all entities that have the same value in this filed. Should it be something like that:

            .add(AuditEntity.property("MyClass.originalId").eq(id))

            or the member "originalId" becomes composite key that contains id, REV?

            • 3. Re: AuditEntity.property ClassCastException
              adamw

              Heh that's a thing I may have overlooked - calling a property originalId. In fact I don't know why I didn't name it with some underscores in the front . I don't have much ideas on how to bypass this right now ... except for renaming the field.

               

              Please create a JIRA, maybe a rename of the synthetic id (e.g. originalId => __originalId) will be needed.

               

              Adam

              • 4. Re: AuditEntity.property ClassCastException
                vipavel

                I'm glad that I haven't committed the field name yet ))) I will give it a different name

                Anyway, what is the JIRA's link?

                 

                Pavel