I have integrated hibernate with my spring webapp
Well this is what i understand from hibernate java doc
onSave is called before an entity is saved or persisted to DB.
preFlush is called before entities are flushed to DB i.e flushed entities are either saved or updated.
createdDate property is only to be set once when the entity is made persistent (satisfied by onSave).
modifiedDate property is to be set when an entity is updated or saved (satisfied by preFlush).
Quote:
If you want to set a value of an attribute in an interceptor, you must use vectors but not entity. I mean, there are three vectors with names, types and values of every properties of an entity. If you want to set the value of a property you have to do it with that vectors.
First you have to obtain the index value of the property name (over propertyNames vector) and then, accessing with that index, you can set the value over state vector.
I want to populate createdDate, modifiedDate property with Date object for all the entities that are being saved or updated
Quote:
If you invoke setter method for the property to be set, it will be not established.
This approach worked for me, the columns are getting updated correctly. My concern is that is it a correct approach to the problem?
If not how to approach this problem correctly?
Quote:
Also is important to return a true value in that interceptor's method to indicate hibernate that the state has been changed by your code.
You are right, but i tried it earlier and it failed to update createdDate, modifiedDate property in DB. Still working on it.