0

I am using PostgreSQL and Hibernate.

I want an entity to be same with Database record. When DB record changes, I want to change the entity I have also.

Is it possible to do such a thing with hibernate.

Thanks

EDIT

Here is my scenario. There are some variables I keep as Application Scope. Normally I store them on the memory.

But now, I want to setup a database server on a machine and two same deployment on two different server. Some times these application scoped variables can change. So, to keep these two servers synchronized, these application scoped variables have to be same.

When one of them updates the entity, I want to know and change the entity on the other server. But I don't want to do keeping select queries to check whether it is changed or not. Some how, I want the entity to change or I want hibernate to tell me it is changed.

I hope, I am clear. If not please let me know. I can provide more info if needed.

Kalyan Vedala
  • 1,049
  • 2
  • 17
  • 33
xxlali
  • 996
  • 2
  • 15
  • 43
  • Hi, Isn't the application making changes to the database? Please clarify your setup. – nomadus May 06 '16 at 14:04
  • I have two servers and both of them use same database. So, when one of them writes to DB, I want the entities I have to be same without keeping do select query. – xxlali May 06 '16 at 14:08
  • Maybe this [read](http://stackoverflow.com/questions/2092327/what-is-the-most-clever-and-easy-approach-to-sync-data-between-multiple-entities) will help you. – MaxG May 06 '16 at 14:27
  • i had the same problem and solved it with WS, for eatch operation, I trigger an other one that do a flush on the variable I have, I had app1 and app2, both of them have app3 included, witch expose WS methods, lets pretend that i have updated a record with app2, this last will call a method from app3(inside app2) that flushes the variable in app1 via app3(inside app1) – Mohamed Nabli May 06 '16 at 14:36
  • there is another efficient way, EXECUTE JAVA CODE FROM Your PostgreSql using a Trigger (after Save) that refresh your variable. and you will be able to notify both application through your database https://tada.github.io/pljava/ – Mohamed Nabli May 06 '16 at 14:49
  • @MohamedNabli actuallty I don't want to use WS for this purpose. But I wonder how can I define a Trigger from PostgreSQL to execute Javacode and is it possible to do this on other RDBMs like MySQL, Oracle etc.. – xxlali May 09 '16 at 08:13

0 Answers0