background preloader

Problems and Solutions

Facebook Twitter

Hibernate LazyInitializationException overcome. In Hibernate, relationships can be defined so that they are "lazily initialized"; i.e., the relationship is only initialized when it is determined that the information contained in the additional table is needed.

Hibernate LazyInitializationException overcome

This is fine as long as it is determined that the information is needed within the current Session. But, what if this is not true? The "traditional" ways of handling this are to either open the Session in the view (which is a very un-MVC concept), get everything at once (forget about lazy loading - but this could end up getting everything), leave the Session open (IMnsHO, a very bad practice), or make sure that you get what you need initially. For the project I'm working on, these "alternatives" would not work. You see, in that project the EMPLOYEE table is lazily associated with the ASSIGNMENT table. Java - Hashmap concurrency issue. Java: iterate through HashMap.