add an example to jdoc of SS.fetch()

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-17 13:27:28 +02:00
parent 0c97bbdb47
commit 5b28d1562e
1 changed files with 7 additions and 1 deletions

View File

@ -267,9 +267,15 @@ public interface StatelessSession extends SharedSessionContract {
/**
* Fetch an association or collection that's configured for lazy loading.
* <pre>
* Book book = session.get(Book.class, isbn); // book is immediately detached
* session.fetch(book.getAuthors()); // fetch the associated authors
* book.getAuthors().forEach(author -> ... ); // iterate the collection
* </pre>
* <p>
* Warning: this operation in a stateless session is quite sensitive
* to data aliasing effects and should be used with great care.
* to data aliasing effects and should be used with great care. It's
* usually better to fetch associations using eager join fetching.
*
* @param association a lazy-loaded association
*