Search code examples
springhibernatelucenehibernate-searchhibernate-envers

Hibernate envers + hibernate-search : Reading audit information over Lucene/Elasticsearhc indexes


I'm using hibernate-envers for audit purposes in an application. I'm also using hibernate-search in order to search/read the information of JPA entities in the application.

I was wondering if there's any kind of configuration/integration that can make hibernate-envers work with the audit enties/tables, over indexes too, in order to read with hibernate -search that information from the indexes.

I would like to avoid doing it "manually", for example, using envers event listeners in order to create/manipulate a new index manually for the audited entity, using a new JPA Entity modelling the Audit entity information including @Indexed annotation, fields etc.).

Ideally was wondering if there's support for envers/search integration out of the box, without custom development, to achieve storing all audit information in new _aud indexes.

Thanks in advance, any piece of advice is appreciated.


Solution

  • It's certainly not possible out of the box.

    If it ever becomes possible, you won't benefit from all the Envers features such as "get me this entity at this revision". You will simply index all the revisions of each entity, and you will only be able to query (and retrieve) these revisions. That would be queries such as "get all revisions of the entity with id 1 where name contained "some text".

    Also, this will not remove the need for audit tables. The indexes will exist in addition to the audit tables.

    That being said, I just gave it a try and we could make it possible in Hibernate Search 6 with just a few changes. If you're still interested, you can have a look there: https://hibernate.atlassian.net/browse/HSEARCH-4238