-->
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.  [ 9 posts ] 
Author Message
 Post subject: Logging DB Changes
PostPosted: Wed Feb 18, 2004 8:22 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
Hi,

I need to log all the changes (insert/update/delete) of my database into a table log. Logging all the fields changed (old and new value) and the tables envolved.

I looked at the hibernate's documentation and saw that probably an interceptor would solve it.

I'd like to know if it's possible to do it and how to do it.
In the interceptor documentation says that into some methods it's not possible to make a connection and not all of them dispose the values of the changed data.

Thanks.

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 10:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the wiki area, there are some samples

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 11:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just to mention, that would be an ideal situation to solve using database triggers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 9:29 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
I looked into wiki area and some more documentation and I realized that an Interceptor won't attend all my needs.

Probably I will have to use LifeCycle... I see two problems for me with it. In the documentation it says in the "onUpdate" method:

"This method is not called every time the object's state is persisted during a flush. "

1) I need it to be called always that it is updated into the database.
Is it possible to do it?

2) And I also need to know who is the table(ok with metadata) and parent table of the register updated.
For example:
Insert into a table SaleItem (register id 5), the parent table is the Sale table - that has a collection of SaleItem.
The table is SaleItem and the parent table is Sale. With all that I still need the ID of the register (5) and the parent(Sale) ID related.

Is there any feature in Hibernate that could help me?

Thanks.

==> because of other needs its not possible to use triggers... I'd like to, but I can't.

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Why won't Interceptor fit your needs? I do this same exact thing and Interceptor is where I do it. You need access to onFlushDirty to catch the event that an instance was been deemed dirty and is about to be synched to the db.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 8:43 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
Well, thinking again, probably the Interceptor fit, but I still have a big problem.

Using the interceptor I'd use 'onDelete' to log the deleted rows, 'onSave' for the inserted rows, and 'onFlushDirty' for the updated rows. Like this I can identify what's the operation executed and write into the DB the data of the operations.

There's no problem with it, right?

What I have a problem is to identify which is the parent object of the one inserted/updated/deleted.
For example:

- ClassA has a collection of ClassB
- an object of classA1 if removed from the colletion classBCollection
- classA1 is updated (with cascade the object classB is deleted).

I need:
- log the changes of classA1
- log the delete of classB, logging also the ID of classA1 with it

I don't know how to get the parent ID... all the rest I presume that work.

Any ideas?

Thanks.

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 3:24 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 11:47 am
Posts: 22
In book Hibernate in Action is on page 346-347 sentence: The Hibernate website also has examples using nested interceptors or logging a complete history (including uptades property and collection information) for a entity.

I am not able to find this example (especially how logging collection information)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 3:29 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
is this what you're searching for?

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 6:47 am 
Beginner
Beginner

Joined: Mon Nov 24, 2003 11:47 am
Posts: 22
curio wrote:
is this what you're searching for?


There is no information about collection.


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