Java 监控数据库的变化 - Hibernate 和 envers

发布于 2024-12-26 04:08:53 字数 230 浏览 3 评论 0原文

我正在编写一个服务器端应用程序来监视数据库的更改,我计划使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2025-01-02 04:08:53

更新:

不,监听器只是 NH​​ibernate 中的钩子,它只监听设置了 Enverslisteners 的 Hibernate 会话所做的更改。

您正在寻找的是触发器或数据库事件。我使用 Triggers、listennotify 对 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 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文