Querying property-level revisions
Description
Activity
Chris Cranford April 11, 2017 at 3:39 PM
This is the query stubs I am proposing for Hibernate Envers 6.0:
/**
* Creates a query that selects the revisions at which the given entity was modified. Unless a
* projection is set, the result will be a list of 4-element arrays, containing the following:
* <ol>
* <li>The entity instance</li>
* <li>Revision entity, corresponding to the revision where the entity was modified. If no custom
* revision entit yis used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}.</li>
* <li>The revision type, an enum of class {@link org.hibernate.envers.RevisionType}.</li>
* <li>The names of the properties changed in this revision</li>
* </ol>
* Additional criterion may be specified to filter the result set.
*
* @param clazz Class of the entities for which to query.
* @param selectDeletedEntities If true, the result set will include revisions where entities were deleted.
*
* @return the audit query
*/
@Incubating(since = "6.0")
public AuditQuery forRevisionsOfEntityWithChanges(Class<?> clazz, boolean selectDeletedEntities);
/**
* Creates a query that selects the revisions at which the given entity was modified. Unless a
* projection is set, the result will be a list of 4-element arrays, containing the following:
* <ol>
* <li>The entity instance</li>
* <li>Revision entity, corresponding to the revision where the entity was modified. If no custom
* revision entit yis used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}.</li>
* <li>The revision type, an enum of class {@link org.hibernate.envers.RevisionType}.</li>
* <li>The names of the properties changed in this revision</li>
* </ol>
* Additional criterion may be specified to filter the result set.
*
* @param clazz Class of the entities for which to query.
* @param entityName Name of the entity (if it can't be guessed basing on the {@code clazz}).
* @param selectDeletedEntities If true, the result set will include revisions where entities were deleted.
*
* @return the audit query
*/
@Incubating(since = "6.0")
public AuditQuery forRevisionsOfEntityWithChanges(Class<?> clazz, String entityName, boolean selectDeletedEntities);
The property change names will require that the entity class identified by clazz
support the use of the modified-flags feature.
The original request stated to capture property names changed during all state changes; however its safe to assume that all properties changed during the add operation and none of them changed during a remove operation. Therefore, the API presently will only return property changes for update operations and not for the other two.
The API is marked @Incubating
so its free to change from release to release (this includes dot releases) until we deem it stable, so any input is greatly welcomed.
Szczepan Kuźniarz February 25, 2017 at 9:43 PM
@Chris Cranford I've missed your comment in July - looking forward for version 6 🙂
@Saul Giordani There is already 4.2 version - check out 4.2.x branch in GitHub. I didn't test it with 4.2.21.Final, but it should work without problems.
Chris Cranford February 22, 2017 at 1:25 PM
@Saul Giordani, from the community perspective, we are no longer maintaining Hibernate 4.x. Even within the 5.x release stream, we typically do not backport features to previous non-master branches unless there is team consensus or a strong community request that it makes sense to do so.
I'm going to go ahead and tentatively add 6.0.0.alpha1 to this issue, at least that gives you and others an idea when to likely expect it. If we decide to do another point-release of version 5.x and the code is ready, I may backport it to that.
Regarding 4.2.x support, if the author of the extension code base at https://github.com/skuzniarz/hibernate-envers-ext wishes to make a version that is available for 4.2.x users, they're welcomed to do so; however, I won't be officially on the community fork.
Saul Giordani February 21, 2017 at 9:05 AM
Hello, do you know if there is any way to implement this functionality in a project with hibernate 4.2.x?
Unfortunately, I can't upgrade hibernate right now.
Thanks
Chris Cranford June 12, 2016 at 2:30 PMEdited
@Szczepan Kuźniarz, I'll look to see if it makes sense to include this into a future 5.2.x or 6.x release. There were some thoughts on improving the Envers query API as we move forward.
It would be useful to get the list of all properties that changed in a revision, together with the type of change (added/modified/deleted).
So far it's only possible to query for revisions where some specified properties have (not) changed, see http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch15.html#envers-tracking-properties-changes.
Backlink: http://stackoverflow.com/questions/9422331/hibernate-envers-revision-info-changes-list