0

Let's assume I have the following entities:

public class Group
{
    public IList<Item> Items { get; set; } 
}

public class Item
{
    public Group Group { get; set; } 

    public string Name { get; set; } 
}

Now I want Envers to create a revision for Group when the Name property of Item has changed. The revision_on_collection_change property just works if I change the collection (as the name suggests ;-) itself.

Is there a possibilty to setup Envers to 'connect' the parent entity with properties of its child element properties?

core
  • 851
  • 1
  • 8
  • 28
  • triggers are your friend. – Daniel A. White Jun 17 '14 at 12:50
  • What for triggers, where to define them? I cannot find anything at the Envers documentation. – core Jun 17 '14 at 13:04
  • I'm sure he means database triggers - code you configure the database to execute which is triggered by various events. For example, you could add a trigger that fires whenever Item changes are inserted into the audit table which then inserts the appropriate Group change as well. – Daniel Schilling Jun 18 '14 at 19:09

1 Answers1

1

Short answer: No.

Longer answer: Depending on your use case there are alternatives that might suit your needs. Either make sure that your Group entity will be modified when one of its Items are or include revisions with modified Items when querying for a Group (the latter would probably need your relation to be bidirectional though).

Roger
  • 1,944
  • 1
  • 11
  • 17
  • Thanks for your answer. The relation is already bidirectional. Could you give me an hint how to include revisions with modified items while querying? – core Jun 18 '14 at 06:53
  • Roger, I am still searching for a solution of this problem. Please could you help me? – core Jul 31 '14 at 08:37
  • As said, envers doesnt support this. But you can of course make sure that parent always be modifies each time a child is (either interceptor/event listeners or fix it in your domain model). Or, maybe, you can query the children to get the revisions where they have been changed and then make a query on parent using these revision numbers. – Roger Jul 31 '14 at 18:39