-->
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.  [ 4 posts ] 
Author Message
 Post subject: manage historic for object
PostPosted: Mon Feb 09, 2004 9:14 am 
Newbie

Joined: Mon Feb 09, 2004 8:58 am
Posts: 4
Hi,

I have objects for which i must keep traces for each change done on attributs or relations (0-*)
for exemple
the class A is persistant and has one attributs (is name for example)
the class B is persistant and has relationship with A of type one-to-many (so a foreign key is created in A table)

1) when i save A i want to save halso an object of kind HistoricItem when precises that a new object is created
2) when i reload A and change the name and save i want to save halso an object of kind HistoricItem when precises that the object is change
3) when i add a A object to a B object, i want to to save halso an object of kind HistoricItem when precises that the A object has change

to do this i use a Interceptor implementation. 1) and 2) is done correctly and automatically
but for 3) i have a problem : information received in Interceptor never says that the A object has changed. And never says that the B object has changed

the surprise is that in the onFlushDirty method the content currentState and previousState is the same for the set of A object contained into the B object

could any one help ?
notice that my hibernate release is 2.0.3

Regards
Florent


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 10:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The interceptor *does* fire if it is a bidirectional association, or if the parent is versioned.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 1:45 am 
Newbie

Joined: Fri Aug 29, 2003 3:28 am
Posts: 4
I have also encountered the problem that the previous and current states for a collection are identical (the updated state) in the onFlushDirty interceptor.

My guess is that hibernate only keeps track of references, so that when you modify the collection, you are not changing the 'previous' reference and thus it still points to the modified collection.

A workaround for this is to create a new instance of the collection class whenever you want to modify it. If you're worried about allocating a new object each time, then track when you have the hibernate implementation class and allocate a new collection only then. The previous state will then reference the old hibernate collection and the current state your newly allocated one.

Note however that reallocating hibernate collections is generally considered bad form and won't work for an all-delete-orphan cascade.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 3:10 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I think trigger is better way to implement it. You do not need "HistoricItem" in model and it will work with all RDMS clients.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.