2 Replies Latest reply on Mar 25, 2007 8:03 PM by Adrian Mitev

    Hibernate and Ajax

    demetrio812 Apprentice

      Hi,
      untill now I always user the 1 Session per Session pattern to manage Hibernate session in JSF.

      Today I tried to convert an existing application (JSF 1.2, Facelets, Ajax4Jsf, RichFaces) to 1 Session per Request pattern.

      I installed an ORM Filter that open and close the session, this works good in non-ajax application: when I want to use a detached object I just call session.lock(obj, LockMode.NONE) to reattach it after using.

      Now there are problems in this application. I didn't understand very good where is the trick but in some case it did not close the session (it seems that if I make an ajax request the orm filter is bypassed, so in the next request when I call lock hibernate give me a NonUniqueObject exception).

      I tried to lock before using it and evict after, but there is some problem with evict cascade (I set the configuration but I don't know why it seems it doesn't work, so I have to manually evict all the subobject I used and loaded with lazy fetch).

      Is there a better pattern? May I can use a phase listener so that the close session works for ajax and non-ajax request? And is it good to close and re-open the session in every ajax request?

      Thanks a lot for you answers and sorry for making so many! :D

      Demetrio Filocamo