File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Can I be informed of a database update? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Can I be informed of a database update?" Watch "Can I be informed of a database update?" New topic

Can I be informed of a database update?

Robert Miller
Ranch Hand

Joined: Jun 18, 2004
Posts: 56
I'm looking into using Hibernate for a database project. We intend to have multiple clients on multiple systems making updates to the database, and we also want a task to be started on a particular system whenever a particular table is updated.

I've looked through Hibernate documentation and it looks like an Interceptor might solve our problem, but it says an Interceptor is started when the session updates the database. Does that mean it will only intercept updates by that particular process? I need a way to be informed of any update.

If an interceptor can't be triggered by a general update, is there something else that will work?

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

The Interceptor can tell you when an property on a persistent object is changed within the context of a particular Session or SessionFactory. So you could monitor all the data manipulation in one application's SessionFactory. Indeed, if you bound the SessionFactory to JNDI, you could monitor what is happening for every application that gets its SessionFatory from there.

What you can't do is know when another unrelated application updates a database table. The only thing that can tell you that is the database itself, there is no other application or API that can do it. And the only thing that a database is likely to give you to monitor data manipulation is a trigger. Communicating from a database trigger to all listening applications is going to be very awkward.

Some databases allow triggers to make calls to the OS of the host system (such as SQL Server). You could use this sort of machanism to call you process. Other databases such as Oracle support Java, so you could write your process in java and run it in the database.
[ October 03, 2006: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: Can I be informed of a database update?
jQuery in Action, 3rd edition