[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3614) Version Tagging

Adam Warski (JIRA) noreply at atlassian.com
Thu Nov 20 13:44:16 EST 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3614?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31755#action_31755 ] 

Adam Warski commented on HHH-3614:
----------------------------------

Hello,

I think that we first need to consider what isn't possible to achieve right now using a revisions-of-entity query and maximizeProperty().
Executing a query like that:
versionsReader.createQuery().forRevisionsOfEntity(MyEntity.class, false, true)
  .add(VersionsRestrictions.maximizeProperty("revision.id").add(VersionsRestrictions.eq("tag", "OK"))
will return you the newest instance of (any) MyEntity, tagged with "OK". If you additionally add a restriction on the id, you'll get the newest instance of a specific MyEntity, tagged with "OK".

So I think this may solve your issue, if you know the tag at commit time (then, when inserting/updating an entity, you simply set the appropriate tag). Additionaly, whole history of tagging is stored also - you can easily retrieve all entities that were tagged with a specific value, as well as the newest entity tagged with a value.

The special tagging solution may be needed for two reasons:
- performance - executing the query with maximizieProperty may be expensive (it involves a correlated subquery)
- flexibility - you cannot tag an already commited version of an entity

Does the query work for you, or not? If not, why?

If you'd like to develop and contribute it, you're of course very welcome! :)
I think that the best way to develop it (if only), would be as an Envers add-on, so that users may include it in their projects or not. Of course some modification of Envers source code would be needed to provide to be able to write such an add-on.

The EntityTagging would probably need to be bound to an open EntityManager/Session, so you would need an EntityTaggingFactory, similarly to VersionsReader/AuditReader.

Once you have a good idea on the user API (meaning of @Taggable, other annotations, detail content of EntityTagging), I think it may be a good idea to write about them and the whole add-on on the hibernate-dev mailing list to get other's opinion :)

Adam

> Version Tagging
> ---------------
>
>                 Key: HHH-3614
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3614
>             Project: Hibernate Core
>          Issue Type: New Feature
>          Components: envers
>            Reporter: Corneil du Plessis
>
> I would like to suggest a new feature for version tagging in envers.
> I have a suggestion for how it can be implemented.
> @Versioned
> @Taggable
> public class MyEntity {
>      @Id
>     private Long id;
>     @Basic
>     String someProp;
> }
> By implication results in @RevisionTagEntity which can be seen as
> public class MyEntity_tag {
>     @RevisionNumber
>     private Integer version_numer;
>     @RevisionTagTimestamp
>     private long tag_date;
>     @RevisionTagValue
>     private String tag; // Other @Colum can apply as well as using Integer or Enum 
>    // Other properties allow like with @RevisionEntity
> }
> This produces a table like:
>     create table MyEntity_tags (
>         id bigint not null,
>         version_number integer not null,      // version_number is _revision
>         tag_date timestamp not null, // assigned when create or modified 
>         version_tag varchar(255) not null,  // Could be customizable with RevisionTagEntity similar to RevisionEntity
>         primary key (id, version_tag),
>     );
> EntityTagging will be a utility class using EntityManager and Entity or Collection of Entities and do:
> tagLatestVersion(Object entity, String tag)
> tagVersion(Object entity, Integer version, String tag)
> moveTag(Object entity, String targetVersion, String tag)
> determineVersion(Object entity, String tag)
> The following could be added to allow the retrieval of versions of collections of entities that are tagged in a specific way.
> RevisionProperty.tag(String tag)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list