Announcement Announcement Module
Collapse
No announcement yet.
Hibernate lazy initialization in myfaces Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate lazy initialization in myfaces

    Hi,
    I read the many questions/replies/guides about using OpenSessionInViewFilter/Interceptor to bind sessions to threads.
    I set all definitions as written (to the best of my understanding) but still get failed to lazily initialize a collection <...> - no session or session was closed.
    I am using OpenSessionInViewFilter, as most postings regarding this exception were in conjuction with multiple transactions, I guess my problem is error in definition, i thank you for helping me with this.
    the code is working fine with lazy fetching turned off.
    the code executed in the jsp is (the url to access this jsp terminates with .jsf):
    <%
    System.out.println("before init");
    ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesCo ntext.getCurrentInstance());
    QuestionaireService q = (QuestionaireService)ctx.getBean("qservice");
    System.out.println("got service");
    QuestionsCategory qc = q.getRootCategory();
    System.out.println("got root category");
    System.out.println(qc.getChildrenCategories()); // <- exception is thrown here
    System.out.println("got children cats");
    %>

    web.xml:
    <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/faces-config.xml</param-value>
    </init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>3</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletCont extListener</listener-class>
    </listener>
    <listener> <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    applicationContext.xml:
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="configLocation" value="WEB-INF/hibernate.cfg.xml"/>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac leDialect</prop>
    </props>
    </property>
    <property name="configurationClass">
    <value>org.hibernate.cfg.AnnotationConfiguration </value>
    </property>
    <property name="dataSource">
    <ref bean="myDataSource"/>
    </property>
    </bean>

    <bean id="myTransactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref bean="mySessionFactory"/>
    </property>
    </bean>

    <bean id="qDao" class="a.QuestionairesDao">
    <property name="sessionFactory">
    <ref bean="mySessionFactory"/>
    </property>
    </bean>

    <bean id="qservice" class="a.QuestionaireService">
    <property name="transactionManager">
    <ref bean="myTransactionManager"/>
    </property>
    <property name="questionaires">
    <ref bean="qDao"/>
    </property>
    </bean>

    faces-config.xml:
    <variable-resolver>org.springframework.web.jsf.DelegatingVar iableResolver</variable-resolver>
    <locale-config>
    <default-locale>en</default-locale>
    </locale-config>
    </application>

    <managed-bean>
    <managed-bean-name>questionsTree</managed-bean-name>
    <managed-bean-class>a.beans.QuestionsTree</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>questionsService</property-name>
    <value>#{qservice}</value>
    </managed-property>
    </managed-bean>
Working...
X