PDStat
PDStat

Reputation: 5855

Java monitor changes in database - Hibernate and envers

I'm writing a server side application that will monitor changes to a database, I plan to do this with Hibernate. I'd like to set up a listener so that if any changes are made to the data any registered observers can be told there is an update and send a separate request to pull it.

I've read about Hibernate envers as well as the AuditEventListener. My question is though seeing as my application will only get data and not set it, can the Envers listeners listen to changes in tables that are NOT made by my application?

Upvotes: 2

Views: 1554

Answers (1)

Firo
Firo

Reputation: 30813

Updated:

No, listeners are only hooks in NHibernate which only listen on changes made by Hibernate-sessions having the Enverslisteners set.

What you are looking for are triggers or database events. I made a proof of concept with Postgresql using Triggers, listen and notify which seems to work under certain conditions. Although its for Postgresql the Architecture used is the same for every SQL-Database which supports some kind of notification system.

For Oracle:

  • create a callback for changes see here
  • write a change info in some table
  • poll change info table in your app to see if there are changes and process them

Upvotes: 1

Related Questions