Skip to content
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

Fix for NullReferenceException in lazy bidirectional many-to-one properties #53

Closed
wants to merge 2 commits into from

Conversation

DavidUv
Copy link

@DavidUv DavidUv commented Jun 25, 2024

Having a many-to-one bidirectional mapping with lazy properties will result in a NullReferenceException in AuditEventListener. This change to the AuditEventListener will fix this. There is also an accompanying unit test for this.

The underlying problem that triggered the NullReferenceException was due to the fact that the entity name could not be resolved since it was not of the expected type. The type in the case of a lazy property is a <entity name>ProxyForFieldInterceptor and not the actual type of the entity. Using the NHibernate utility method BestGuessEntityName will resolve to the actual entity name thus satisfying the mapping in Envers.

As I am not familiar to the Envers code base I tried to keep the AuditEventListener changes minimal not to disturb the functionality. All tests passes and this fixes the problem but I'm not totally sure how the mapping actually works and the value argument is still of the ProxyForFieldInterceptor type. Could this be a problem?

RogerKratz pushed a commit that referenced this pull request Jun 25, 2024
RogerKratz added a commit that referenced this pull request Jun 25, 2024
@RogerKratz
Copy link
Collaborator

Applied! Thanks!

@RogerKratz RogerKratz closed this Jun 25, 2024
@DavidUv DavidUv deleted the many-to-one-bidirectional branch June 25, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants