I am trying to perform an envers audit query on a many-many relationship. Simplified, my entity mappings looks like the following:
public class Party {
@Audited
@AuditMappedBy(mappedBy = "parties")
@ManyToMany(mappedBy = "parties")
private List<Contact> contacts = new ArrayList<>();
}
public class Contact {
@Audited
@JoinTable(name = "contact_party", <...mappings...>))
private List<Party> parties = new ArrayList<>();
}
I would like to query for audits of Contact, where âpartiesâ contain a given Party. Unfortunately, I receive the error: This type of relation (âŚpackageâŚContact.parties) canât be used in audit query restrictions.
I have seen tickets in relation to this (Jira) and I am running hibernate envers version 6.6.4. The code builds as expected and audit DB entries are created correctly - I just canât figure out a way to query them
Are there plans to support queries of this type? Or, is there a way to query the many-many relationship that I am missing?
Querying for a specific revision doesnât give an error, but at that point I will have negated the purpose of the original code, which is to find all âContactâ audits in a âPartyâ
Ideeally we would have it working via âforRevisionsOfEntityWithChangesâ. Does it sounds like a bug?
I donât know for sure, but to me this looks like a bug, yes. I am no expert on Envers though, so maybe the answer might be âthis is not supported yetâ.
Since Envers uses HQL behind the scenes though, you should be able to formulate whatever query you want by hand.
Also see other answers I gave that discuss this topic: