Java 监控数据库的变化 - Hibernate 和 envers
我正在编写一个服务器端应用程序来监视数据库的更改,我计划使用 Hibernate 来完成此操作。我想设置一个监听器,以便如果对数据进行任何更改,任何注册的观察者都可以知道有更新,并发送单独的请求来拉取它。
我读过有关 Hibernate envers 以及 AuditEventListener 的内容。我的问题是,虽然我的应用程序只会获取数据而不设置数据,但 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:
不,监听器只是 NHibernate 中的钩子,它只监听设置了 Enverslisteners 的 Hibernate 会话所做的更改。
您正在寻找的是触发器或数据库事件。我使用 Triggers、
listen
和notify
对 Postgresql 进行了概念验证,这似乎在某些条件下有效。尽管 Postgresql 所使用的架构对于每个支持某种通知系统的 SQL 数据库都是相同的。对于 Oracle:为
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
andnotify
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: