Hibernate session and Vaadin7

Hello everybody.

I confused again. I have Vaadin 7 web app. I read all topics and chapters about Hibernate + Vaadin and i dont have my answer so far. My problem is especially about LAZY fetching and session handling. There is this situation. Lets say we have editable table. Every row have its own “update” button. Content of table are rows form DB, loaded thought hibernate entity class by new opened session. So i create view and load rows. Cause i have some ManyToMany etc. relations i do not close session so all entitites are persistent. In hibernate i have sessioncontext setted to thread variant.
There are some facts i discovered:

  • Navigation through navagator is NOT handled by specific thread per user
  • Button clicks in loaded view are NOT handled by specific thread per user too

As you can expected all described above cause trouble. By hibernate logic i should use getCurrentSession for persitent object but im not in same thread so it does not work. Or i can open new session but i cant update persistent object in another session, it causes exception. So let say that i close session after gettting all rows for table. But it causes exception of LAZY loaded atributes cause entity is detached now.

I have many questions.
Is my architecture of web app wrong when i want to handle updates under button?
Should i avoid to using LAZY fetching?
Should i create my own implementation of sessionContext with “hibernate session per vaadin session” logic? (I know that there are many problem about closing sessions but i think that is the best solution how avoid many opened hibernate sessions)

I hope i explained my confusion well so we can find proper solution because session per request can not work for Vaadin web apps i hope.

Thx

This is the exact reason why I prefer to use EclipseLink as my JPA provider when working with Vaadin application, it just works out-of-the-box. One thing that at least solves part of the issues is to configure hibernate’s
enable_lazy_load_no_trans
property to true.

Yeah, im new to Hibernate and i wanted to learn it. But how time flows i discover that Hibernate is not for me, is not for my app. I probably use EclipseLink or some other JPA provider as you recommended in your post. Before i change provider ill try change enable_lazy_load_no_trans and will se what happens…

Many thx for your post.