Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change notification on domain objects (Hibernate/Java)

Is there a solution available to subscribe for domain object changes for Hibernate or any other mainstream O/R mapping framework? For example if I have a table in a database called "Apple" I'd like to be able to say "notify me when any Apple object changed" or "notify me when field "colour" of any Apple object changed". Of course I'd expect not just "something changed" notification but rather a list of id's of changed objects or a list of changed objects. Would be nice such solution to be scalable.

to summarize requirements:

  1. All changes to a DB will go through an ORM
  2. It should be a complete solution where it's possible to place a subscription using an expression like "subscribe for Question q where q.title like '%hibernate%'" where "Question" is an entity (Java object mapped to a table in a database) I'm interested in updates for. No need to be a string query but there should be a generic way to place a request.
like image 687
Vladimir Avatar asked Oct 20 '25 08:10

Vladimir


1 Answers

Will all the changes that generate these notifications go through the ORM, or is it possible that data might be changed via JDBC or another application accessing the same database?

If all changes go through the ORM and you are using Hibernate, then you could use Hibernate's interceptors and events.

On the other hand, if all the changes to the data don't go through the ORM and the code that processes the notifications is fairly simple, database triggers might be a better bet.

like image 115
Dónal Avatar answered Oct 22 '25 22:10

Dónal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!