Spring Data JPA
  1. Spring Data JPA
  2. DATAJPA-7

Add possibility to integrate versioning infrastructure like Hibernate Envers

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2 GA
    • Component/s: Core
    • Labels:
      None

      Description

      The auditing capabilities currently serve rudimentary requirements of tracking who created and modified entities. However there are more sophisticated frameworks like Hibernate Envers out there that transparently create revisions for all entities saved and allows accessing those in direct entity access as well as triggering queries on a particular revision. So a potential support for something like this is two fold. First we have to have an extension of Repository interface with methods like:

      T findById(ID id, Object revision);
      
      List<T> findAll(Object revision);
      

      On the other hand the query execution engine could be made aware of the revision a query shall be run against:

      List<User> findByUsername(String username, @Revision Object revision);
      

      As Envers is just one potential candidate we'd have to make the actual versioning library pluggable.

        Issue Links

          Activity

          Hide
          Nicholas Padilla added a comment -

          I'd really like to see this implemented as well. I don't like having to use ORM specific features and since I am using Spring Data for everything else it makes sense to use a "history" feature as well. I have the Audit set up working and now trying to formulate a plan for dealing with the history aspect of this.

          In most use cases you will want to get all revisions of a particular entity, to display for end user viewing of the changes, not just a single revision. All other methods should return just the latest revision. Although, having an ability(as you have laid out) to get a specific revision to maybe update or roll back changes to a that revision would be helpful. Or maybe just providing a rollback function that will do the rollback for you would be even nicer.

          Maybe we could create another Repository that is HistoricalRepository that we can add to the current entity repository or to a new HistoricalRepository that a new class would extend for the same entity. This way we can have a separation of concerns and not bloat a SimpleJpaRepository (or JpaRepository which already has lots of methods) with additional clutter. If an end user wants to perform all functions in the same class, that ability is still there but not required. I will be looking more at this next week, I'll pull down the spring data repo and see what this feature will take.

          Show
          Nicholas Padilla added a comment - I'd really like to see this implemented as well. I don't like having to use ORM specific features and since I am using Spring Data for everything else it makes sense to use a "history" feature as well. I have the Audit set up working and now trying to formulate a plan for dealing with the history aspect of this. In most use cases you will want to get all revisions of a particular entity, to display for end user viewing of the changes, not just a single revision. All other methods should return just the latest revision. Although, having an ability(as you have laid out) to get a specific revision to maybe update or roll back changes to a that revision would be helpful. Or maybe just providing a rollback function that will do the rollback for you would be even nicer. Maybe we could create another Repository that is HistoricalRepository that we can add to the current entity repository or to a new HistoricalRepository that a new class would extend for the same entity. This way we can have a separation of concerns and not bloat a SimpleJpaRepository (or JpaRepository which already has lots of methods) with additional clutter. If an end user wants to perform all functions in the same class, that ability is still there but not required. I will be looking more at this next week, I'll pull down the spring data repo and see what this feature will take.
          Hide
          Oliver Gierke added a comment -

          You might wanna take a look at the Spring Data Envers project and see in how far this actually helps you already.

          Show
          Oliver Gierke added a comment - You might wanna take a look at the Spring Data Envers project and see in how far this actually helps you already.
          Hide
          Nicholas Padilla added a comment -

          Hey Oliver!

          Thanks for the heads up! However, it looks like you are using a Hibernate specific implementation. I am using EclipseLink and am not sure if the mismatch will work. Hibernate is not really my first choice. Let me know if eclipselink will work with this module or not, that way I don't have to spend that time! If anything I will test it out and see if I can take it anywhere. If it fails then I will use it as reference code to implement an eclipselink specific variation.

          EclipseLink uses session events to implement its history tracking: http://wiki.eclipse.org/Introduction_to_EclipseLink_Sessions_%28ELUG%29#Table_83-2.

          Show
          Nicholas Padilla added a comment - Hey Oliver! Thanks for the heads up! However, it looks like you are using a Hibernate specific implementation. I am using EclipseLink and am not sure if the mismatch will work. Hibernate is not really my first choice. Let me know if eclipselink will work with this module or not, that way I don't have to spend that time! If anything I will test it out and see if I can take it anywhere. If it fails then I will use it as reference code to implement an eclipselink specific variation. EclipseLink uses session events to implement its history tracking: http://wiki.eclipse.org/Introduction_to_EclipseLink_Sessions_%28ELUG%29#Table_83-2 .
          Hide
          Oliver Gierke added a comment -

          Closing this as fixed as we have a Hibernate Envers specific implementation in place with the Spring Data Envers project. Adding additional implementations based on other JPA providers versioning infrastructure should be tracked with tickets in Spring Data Commons with requests (or even started implementations) for concrete implementations.

          Marking this as fixed agains 1.2 GA as there will be a release of Spring Data Envers based on this Spring Data JPA version.

          Show
          Oliver Gierke added a comment - Closing this as fixed as we have a Hibernate Envers specific implementation in place with the Spring Data Envers project. Adding additional implementations based on other JPA providers versioning infrastructure should be tracked with tickets in Spring Data Commons with requests (or even started implementations) for concrete implementations. Marking this as fixed agains 1.2 GA as there will be a release of Spring Data Envers based on this Spring Data JPA version.
          Hide
          Oliver Gierke added a comment -

          Closing this as fixed as we have a Hibernate Envers specific implementation in place with the Spring Data Envers project. Adding additional implementations based on other JPA providers versioning infrastructure should be tracked with tickets in Spring Data Commons with requests (or even started implementations) for concrete implementations.

          Marking this as fixed agains 1.2 GA as there will be a release of Spring Data Envers based on this Spring Data JPA version.

          Show
          Oliver Gierke added a comment - Closing this as fixed as we have a Hibernate Envers specific implementation in place with the Spring Data Envers project. Adding additional implementations based on other JPA providers versioning infrastructure should be tracked with tickets in Spring Data Commons with requests (or even started implementations) for concrete implementations. Marking this as fixed agains 1.2 GA as there will be a release of Spring Data Envers based on this Spring Data JPA version.

            People

            • Assignee:
              Oliver Gierke
              Reporter:
              Oliver Gierke
            • Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: