-
Notifications
You must be signed in to change notification settings - Fork 100
Custom RevisionEntity class fails to provide RevisionNumber
and RevisionTimestamp
#250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Never mind the issue - silly me didn't read up on the Hibernate |
THANK YOU! |
Thank you @androidbod, adding |
@albertus82 By some coincidence I'm implementing a custom revision entity today as well - do you know if there is a way to avoid the n+1 query problem with |
@AlexandreCassagne - I don't think there is a way to avoid the n+1 query 'problem' when using I would recommend to query revision information in a paginated fashion which should limit this problem by limiting the amount of revisions retrieved from the database for a single This will only mitigate the problem - it will not solve it. The |
@androidbod I'm not sure of this. I noticed that using the |
@albertus82 I trust you on that - I assume that Custom RevisionEntites are handled differently from the DefaultRevisionEntity - they are definitly handled differently by Spring (see original Issue description) but they are likely to be handled differnently by Hibernate as well. I would have assumed for Hibernate to just Update See: https://docs.jboss.org/envers/docs/ Skimmed the Hibernate Envers Quickstart guide docs - nothing that would indicate that Hibernate handles Custom Revision Entites differently - but that does not mean that Hibernate doesn't handle them differently. |
I have an issue with Spring Data Envers when using a Custom RevisionEntity class for storing revision information in Hibernate Envers.
Here is my Custom RevisionEntity - works well with an H2 Database for testing purposes - up to Spring Boot 2.2.7 it worked flawlessly.
I'm using a custom revision entity to allow for more than
int
limited number of revisions - hence I'm not using Hibernate'sDefaultRevisionEntity
- an extension of this class would not allow for changing the@RevisionNumber
field type.For Spring Boot 2.3.X (tested with 2.3.1 and 2.3.2):
Spring Data Envers'
EnversRevisionRepositoryImpl
uses theAnnotationRevisionMetadata
class to extract and provide revision metadata for any revision loaded from the database. Through debugging I found out that, when aAnnotationRevisionMetadata
instance is constructed for a revision, the@RevisionNumber
and the@RevisionTimestamp
field values are available, however the static methods constructing the respectiveLazy
suppliers will only provide appropriateSupplier
functions for this information.Somehow in the timespan from construction of these
Lazy
suppliers to actual usage of these suppliers, the information is "lost" along the way - currently I assume it has something to do with the fact, that myCustomRevisionEntity
is in fact aHibernateProxy
of the actualCustomRevisionEntity
instance.Generally this seems to have something to do with the deferred loading that is happening through the respectively constructed
Lazy
suppliers operating on theseHibernateProxy
objects which are liable to "loose" some information in the previously described timespan (possibly different Hibernate Sessions for Entity and Revision Infomation loading ? - just a thought).I've tried wrapping the respective
EnversRevisionRepositoryImpl
calls into transactional business methods, butTransationContext
or not - the result remains unchanged - the revision number and timestamp are not available for use after theEnversRevisionRepositoryImpl
getRevision information methods return their respective result.One possible solution that occured to me would be to call
Hibernate.unproxy
on theentity
constructor parameter of theAnnotationRevisionMetadata
fromEnversRevisionRepositoryImpl.createRevisionMetadata
.I've tested that idea - it works - though I'm unsure if there are any performance related side effects from that solution.
I'm also considering whether or not the
DefaultRevisionEntity
provided by Envers could be subject to the same issue of being returned by Hibernate as aHibernateProxy
instance.If there are any questions, please contact me through Github.
Thank you
The text was updated successfully, but these errors were encountered: