Multiple choice technology programming languages

It is possible to re-load an object and all its collections at any time, using the xxxx() method. This is useful when database triggers are used to initialize some of the properties of the object.What is the xxxx() method ?

  1. a) refresh();

  2. b) flush();

  3. c) fetch();

  4. d) load()

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The refresh() method re-loads an object and all its collections from the database, overwriting the current state in the Session. This is particularly useful when database triggers initialize or modify properties after the initial save - refresh() retrieves those trigger-generated values. Option A correctly identifies refresh(). Option B (flush) synchronizes the Session state to the database (writes to DB, not reads from it). Options C and D are incorrect because there's no standard fetch() method, and load() retrieves only if already in Session or throws exception.

AI explanation

Hibernate's Session.refresh(object) re-reads an object's state (and its collections) from the database, overwriting any in-memory values. This is exactly what you need when a database trigger changes column values on insert/update, since Hibernate's session cache otherwise has no way to know the row changed underneath it. flush() pushes changes to the DB rather than pulling them, and fetch()/load() aren't the right API for reloading an already-attached object.