Envers and parent / child relationship

678 views
Skip to first unread message

Chris Richards

unread,
Mar 14, 2011, 12:08:39 PM3/14/11
to nhusers
Using Envers, if I have a parent / child relationship is it possible
to up the version of the parent entity if a property on a child entity
is modified? For example, if I had a Quote parent entity with a
collection of QuoteDetail child entities, when a property on a
QuoteDetail is modified then both QuoteDetail and the parent Quote
have their revision number updated.

Fabio Maulo

unread,
Mar 14, 2011, 1:54:25 PM3/14/11
to nhu...@googlegroups.com
Envers is not about "single entity version", it is about "whole domain state version".
The REV in Envers is like the revision in SVN.
A revision is about the state of the whole domain under audit.


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Roger Kratz

unread,
Mar 14, 2011, 2:44:27 PM3/14/11
to nhu...@googlegroups.com
Chris,

Without knowing why you want this, maybe this thread http://community.jboss.org/message/567412 (the thread is true also for NHibernate Envers) can give you some understanding about this.

/Roger


________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Fabio Maulo [fabio...@gmail.com]
Skickat: den 14 mars 2011 18:54
Till: nhu...@googlegroups.com
Ämne: Re: [nhusers] Envers and parent / child relationship

Envers is not about "single entity version", it is about "whole domain state version".
The REV in Envers is like the revision in SVN.
A revision is about the state of the whole domain under audit.

On Mon, Mar 14, 2011 at 1:08 PM, Chris Richards <chris.r...@yellowfeather.co.uk<mailto:chris.r...@yellowfeather.co.uk>> wrote:
Using Envers, if I have a parent / child relationship is it possible
to up the version of the parent entity if a property on a child entity
is modified? For example, if I had a Quote parent entity with a
collection of QuoteDetail child entities, when a property on a
QuoteDetail is modified then both QuoteDetail and the parent Quote
have their revision number updated.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.

To post to this group, send email to nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com<mailto:nhusers%2Bunsu...@googlegroups.com>.

Chris Richards

unread,
Mar 15, 2011, 5:50:59 AM3/15/11
to nhusers
I was thinking of how best to allow an end user to view the history of
changes, and I think it would be best to show or access this via the
parent entity. As suggested in the link Roger gave, a better solution
would be to be able to get all the revisions for a parent entity and
its child entities in a single query. So you could have something
like:

auditReader.GetRevisions<Quote>(quoteId, q => q.Details);

which would return the revisions for a Quote and all the revisions for
the associated QuoteDetails.

Would it be possible to implement this using an AuditQuery?

Chris

On Mar 14, 6:44 pm, Roger Kratz <Roger.Kr...@teleopti.com> wrote:
> Chris,
>
> Without knowing why you want this, maybe this threadhttp://community.jboss.org/message/567412(the thread is true also for NHibernate Envers) can give you some understanding about this.
>
> /Roger
>
> ________________________________
> Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Fabio Maulo [fabioma...@gmail.com]
> Skickat: den 14 mars 2011 18:54
> Till: nhu...@googlegroups.com
> Ämne: Re: [nhusers] Envers and parent / child relationship
>
> Envers is not about "single entity version", it is about "whole domain state version".
> The REV in Envers is like the revision in SVN.
> A revision is about the state of the whole domain under audit.
>
> On Mon, Mar 14, 2011 at 1:08 PM, Chris Richards <chris.richa...@yellowfeather.co.uk<mailto:chris.richa...@yellowfeather.co.uk>> wrote:
> Using Envers, if I have a parent / child relationship is it possible
> to up the version of the parent entity if a property on a child entity
> is modified? For example,  if I had a Quote parent entity with a
> collection of QuoteDetail child entities, when a property on a
> QuoteDetail is modified then both QuoteDetail and the parent Quote
> have their revision number updated.
>
> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To post to this group, send email to nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>.
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com<mailto:nhusers%2Bunsubscribe@googlegro ups.com>.
> For more options, visit this group athttp://groups.google.com/group/nhusers?hl=en.

Roger Kratz

unread,
Mar 15, 2011, 6:59:32 AM3/15/11
to nhu...@googlegroups.com
I'm thinking out loud here...

If Envers would offer an API like your proposal, I would guess it wouldn't take long before it ain't enough... Probably someone needs q.Detail.DetailInfo to be included as well -> you need to be able to define a big tree of entities. I will think about this...

Anyhow, even today you should probably be able to do what you want if you get the revisions for your quote entity followed by a query (queries ?) to get appropriate revisions for quotedetails. Have a look at https://bitbucket.org/RogerKratz/nhibernate.envers/src/9ecad0c2289a/Src/NHibernate.Envers.Tests/Integration/Query/RevisionConstraintQueryTest.cs.
Then you will have all affected revisions for Quote and QuoteDetails.

I don't say this is optimal though. A first good step for this situation would be to port audit strategy (http://216.121.112.228/browse/NHE-1) which gives the user the possibility not only persist an audit date but also an end date. That way queries like this would be easier. I hope I will find the time for this port "soon" (day, week or month - don't know ;)).

/Roger

Fabio Maulo

unread,
Mar 15, 2011, 7:45:18 AM3/15/11
to nhu...@googlegroups.com
The user can ask for:
give me the situation of Quote#12345 between 2011/01/01 and 2011/02/28.
(#12345 is the ID)

Then you can ask for all REV between 2011/01/01 and 2011/02/28 and then you can show the whole Quote#12345 graph history.

For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Chris Richards

unread,
Mar 15, 2011, 8:01:40 AM3/15/11
to nhusers
Roger you are right, it would need careful thought to avoid misuse of
the API. Not sure if it has been implemented in the Java version, but
that is what was suggested in the thread that you linked to earlier.

I have a real need for versioning and will look at prototyping
something in the next week or so. As it stands at the moment your port
of Envers will be a great help, and the validity audit strategy, when
it comes, even more so.

Thanks,
Chris
Reply all
Reply to author
Forward
0 new messages