-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: intercepting changes on associated objects ?
PostPosted: Tue Apr 29, 2008 6:33 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Hellu all,

I like to intercept the changes on an associated object, but don't know how.

Example: Person has a collection of adresses. The addresses are value type objects. I want to change the date created/date updated fields in the address, just before they are updated in the db.

In the hibernate interceptor the onSave method get called whenever Person is saved, but not when Address is saved.

Then you have the methods onCollectionRecreate and onCollectionUpdate that I think should be used for this purpose, but I don't really understand their usage.

For example, the signature of one of them:
Code:
onCollectionUpdate(Object collection, Serializable key)


But the key is unknown as it's the person Id, but that's the foreign key and we can't use that in our collection that only contains Addresses and doesn't have any method to retrieve the object through this user id...
Also I noticed that this method receive the whole collection, so also the Addresses that aren't changed...

Hmmm... I noticed some other people had the questions about this usage as well, but never got an answer..

So I hope I have more luck and somebody can give me a bit of advice on this subject.

I read the Auditable examples in the books and wiki, but they don't talk about associations...

Regards,
Ed


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 9:10 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
(I can't find where I did this in the past so don't shoot me if I get it a bit off...)

You should be able to cast your collection to PersistentSet/List/whatever in any Interceptor method that you see fit. Once you cast to PersistentSet, you'll see a getStoredSnapshot() method that represents the original state of the (in this case) Set. You can use this to walk over the set or check the size, etc...

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 4:05 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Thanks,

But I will just solve it in the database. It's a bit too complex to solve it through Hibernate.
I don't want to walk through the whole collection to find out which one changed...

Ed


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 22, 2008 9:28 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Hellu,

I thought I could do it "easily" with a trigger.
However, I forgot that means that Hibernate has to perform a refresh which I don't like.

Anyway: this still means that I would like to use the method "onCollectionUpdate" from the interceptor to detect which objects are modified and to set their modified date field.

Please some help on how to do this, as I don't understand how to detect which objects are modified ?

Cheers,
Ed


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 30, 2008 9:59 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Please some help on this topic, as I really don't know how to deal with it and can't find any documentation about the topic ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.