I wish I knew what exactly does each item in this list, how it works, what the consequences and when is the correct time to use.
- Refresh
- Evict
- Replicate
- Flush
I even wonder what each one does, but I’m not absolutely sure, so I’m asking for your help, cause I really want to understand it.
I know it’s a pretty generic question, but I think really useful to know about it all.
Thanks.
The Hibernate Documentation gives good examples of this. Also this blog post will give you some insight. I will add some line from there below.
It is possible to re-load an object and all its collections at any time, using the
refresh()method. This is useful when database triggers are used to initialize some of the properties of the object.see here for more examples.
Whenever you pass an object to
save(), update() or saveOrUpdate(), and whenever you retrieve an object usingload(), get(), list(), iterate() or scroll(), that object is added to the internal cache of the Session.When
flush()is subsequently called, the state of that object will be synchronized with the database. If you do not want this synchronization to occur, or if you are processing a huge number of objects and need to manage memory efficiently, theevict()method can be used to remove the object and its collections from the first-level cache.Read the complete example from here.
Read about the session API here.