How Hibernate.initialize() works

The difference is in scope of application.

The reason for making a collection association lazy is to avoid having it load the collection every time the parent object is loaded if you don’t really need it.

If you are lazy-loading a collection normally, but for a particular use, you need to ensure the collection has been loaded before the session is closed, you can use Hibernate.initialize(Object obj) as you noted.

If you in fact always need the collection loaded, you should indeed load it eagerly. In most software though, that isn’t the case.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)