3 Replies Latest reply on Oct 19, 2011 2:14 PM by Leo van den berg

    Close session in view

    Adriano Pamplona Newbie


      At first, sorry my English, it isn't as good as I want.

      I have been using seam in my projects and I have a little problem, I would like to close the session in view in order to avoid hibernate proxy to select some records, I want to do the correct query in DAO's, using fetch.

      I know that I want can show me LazyInitializationError if I get a lazy collection from an object, but I would like to do this.

      Does someone can help me??


        • 1. Re: Close session in view
          Aldo Bonzi Novice

          We can't help you if relevant source code isn't posted. In the mean time may be this can help you

          • 2. Re: Close session in view
            Adriano Pamplona Newbie

            The problem is conceptual, when I use

            <h:outputText value="#{entity.objectAttribute.name}"/>

            in my XHTML, hibernate do another select of 'objectAttribute' because the 'objectAttribute' is mapped by LAZY. I did not want this, I want the programmer build the HQL's in DAO's instead of let hibernate do this another select.

            In order of that I would like to close the hibernate session in Facade layer.

            My architecture is XHTML / Controller (ManagedBeans) / Facade / BO / DAO.

            This problem is because I have been working in a project that has a big performance problem, we discovered that application do a lot of selects, the programmers did not build a good HQL.

            For example, if a build a select like 'from Product' and the Product agregate 'productType' as a lazy object, when the XHTML invoke getProductType the hibernate proxy will do another select to retrieve ProductType, If the main select retrieve 200 records, the total select count will be 201 select because is 1 main select and 1 select from each record in order to retrieve producttype.

            But if I build the select like 'from Product p left outer join p.productType' will be only  one select with left join.

            Could someone help me?

            • 3. Re: Close session in view
              Leo van den berg Master


              When the association is mapped Lazy, Hibernate will not read the other entity unless you do a join. If you want the entity also LOADED, you need to add the fetch keyword after the join. This will take care of loading. See the hibernate docs for a full explanation of this feature.


              P.S. this is really a basic Hibernate question, so you should ask there.