7 Replies Latest reply on Oct 17, 2008 10:16 AM by adamw

    missin column on VersionsQuery

    sannegrinovero

      I'm using 1.1.0.beta2
      and I have simple entity were I wanted to@Versioned just one @ManyToOne DomainOwner property, and have another String property which is the business key.

      @Id
      Long id;
      
      @Versioned @ManyToOne
      DomainOwner owner;
      
      String domainName; //not versioned and business key
      
      //only equals and hashcode below

      The "x_versions" table is looking good, exactly what I was expecting: the needed keys, the versioning info, and only one extra column for the owner_id.
      but then I make a query using
      VersionsQuery query = vReader.createQuery().forEntitiesAtRevision(Domain.class, revision);
      query.add( VersionsRestrictions.eq( "domainName", name ) );
      Domain domain = (Domain) query.getSingleResult();


      And I get a SQL exception, stating the column "domainName" doesn't exist in the versioning table. My Db is right, I think Enverse should join with the entity table, to have all columns?
      Shouldn't it make a selection statement to have all unversioned data from one and all versioned data on the other?

      My current workaound has been to but @Versioned on domainName too.. but it's looking a bit silly to have both @Versioned and @Immutable on the same prop, even more as it's a business key.

        • 1. Re: missin column on VersionsQuery
          adamw

          Hello,

          currently, the data is not joined, so if you read versioned entities, you only get the data that is versioned. I admit that joining with the original entity to have the immutable business key makes sense. If it doesn't change, making it versioned only wastes space. One problem I see here, is what would happen if you delete the entity? You would still be able to read the history, but you wouldn't be able to get the business key.

          Adam

          • 2. Re: missin column on VersionsQuery
            sannegrinovero

             

            what would happen if you delete the entity? You would still be able to read the history, but you wouldn't be able to get the business key.

            In my case, I won't ever delete it, or if I do it really was a mistake to enter it.

            In a more general case I suppose that the designer should understand that, as he didn't version some data, it won't be possible to
            1)get an older version (seems obvious)
            2)get it as it was before deletion (is a logic consequence of point 1)

            IMHO it is quite accepatble, if it isn't they should version all data.

            • 3. Re: missin column on VersionsQuery
              adamw

              Hello,

              yeah, if you delete the entity you can't expect to have the full data :) There are several options on turning on the possibility to join the historic entity with the "current" entity. One is an switch when creating queries - but then, you wouldn't get the joining when doing find() or traversing relations. The other is a global configuration option (to turn it on or off for all entities). The third is an annotation on the entity, for example "@JoinWithCurrent" (or just on some fields?). What do you think?

              The deleted entities would pose still some problems in the general case, when selecting entities, but I think a left join should be enough to solve it :)

              Anyway, please create a jira feature request :)

              Adam

              • 4. Re: missin column on VersionsQuery
                sannegrinovero

                Hi Adam,
                thank you very much for sharing your thoughts, but I don't have all this experience on your project to really follow the implications of these changes;
                I appreciate your explanations however.

                What I think is that if someone is using @Versioned on an entity he would expect to find the entity in history, but in these cases as only a property is begin "@versioned" you shouldn't be able to retrieve an older version of the entity, but should be able to get the state of versioned property.

                So couldn't this all be made transparent to the user (developer using Envers)?

                here is the JIRA: https://jira.jboss.org/jira/browse/ENVERS-59

                thanks for letting me open it; I will send a testcase next week, I'm sorry I am too busy this one.

                • 5. Re: missin column on VersionsQuery
                  adamw

                  Hello,

                  a test case would be great :)

                  So you would expect to:
                  - be able to specify restrictions on non-versioned properties in queries
                  - when reading a versioned entity, to have all non-versioned fields filled with "current" data, unless the entity is deleted.

                  Did I understand correctly?

                  --
                  Adam

                  • 6. Re: missin column on VersionsQuery
                    sannegrinovero

                    yes, I think that makes sense.

                    Maybe when I'll send the testcase it will appear more clear why this is very useful.

                    • 7. Re: missin column on VersionsQuery
                      adamw

                      Ok :)
                      I guess it will be mainly useful in the presence of an immutable business key.

                      --
                      Adam