Reputation: 2332
I have a database trigger which executes on insertion of data. From the application end, I use hibernate to update the same table which is update by the database TRIGGER. The data which was updated by Trigger gets overwritten by the older data when I update the data from the application end.I figured out that the cached value in hibernate is not in sych with the value from the database. Is there a proper way to get around this? The cache I am talking about is First level cache.
EDIT - Hibernate should update certain fields in the database and other fields in the database should be updated by the TRIGGER. Is this possible?
Upvotes: 0
Views: 401
Reputation: 2332
My issue was really what is mentioned in the EDIT of the question. The simple solution to the problem is as mentioned by Vlad in the comments. Mark the columns as @Column(name = "dob", insertable = false, updatable = false). This is help avoid any major surprises if hibernate updates the table.
Upvotes: 0
Reputation: 154130
You can use refresh:
session.merge(entity);
session.flush();
//the trigger has been called
session.refresh(entity);
//the entity will reflect the trigger changes
Upvotes: 1