Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Lazy loading without Servlet Filter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Lazy loading without Servlet Filter

    Hi,

    I must use the lazy loading feature from Hibernate 3 within my client application.

    I use the Spring's AOP TransactionInterceptor as described in chapter 11.2.6 at Spring Docs.

    at the spring api docs I read that lazy loading only works with a open session, but how can I use this feature without the OpenSessionIviewFilter ??

    thanks.

    mfg Gideon

  • #2
    You can use the OpenSessionInViewInterceptor. http://static.springframework.org/sp...terceptor.html

    It will wrap your normal beans with a hibernate session.

    Comment


    • #3
      Hi,

      thank you for your hint.

      but it does not work for me, this is my configuration:
      Code:
      	<bean id="myHibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
      		<property name="sessionFactory"><ref bean="sessionFactory"/></property>
      		<property name="entityInterceptorBeanName"><value>sessionInterceptor</value></property>
          </bean> 
      
      
      	<!-- Hibernate SessionFactory -->
      	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      		<!-- property name="jtaTransactionManager"><ref bean="transactionManager"/></property-->
      		<property name="dataSource"><ref local="dataSource"/></property>		
      		<property name="mappingResources">
      			<list>
      				<value>de.mk.user.hbm.xml</value>
      				<value>de.mk.srb.model.hbm.xml</value>
      			</list>
      		</property>
      		<property name="hibernateProperties">
      			<props>
      				<prop key="hibernate.dialect">$&#123;hibernate.dialect&#125;</prop>
      				<prop key="hibernate.show_sql">true</prop>
      			</props>
      		</property>
      	</bean>
      	
      	<bean name="sessionInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
      		<property name="sessionFactory"><ref bean="sessionFactory"/></property>
      	</bean>
      has anyone any idee what I have maked wrong?

      thanks.

      ys Gideon

      Comment


      • #4
        You must wrap your business beans with the interceptor. It is not enough to actually declare it:

        <bean name="myUrl.htm" class="org.springframework.aop.framework.ProxyFact oryBean">
        <property name="proxyInterfaces">
        <value>org.springframework.web.servlet.mvc.Control ler</value>
        </property>
        <property name="interceptorNames">
        <list>
        <value>transactionInterceptor</value>
        <value>myActualController</value>
        </list>
        </property>
        </bean>

        Comment


        • #5
          your example is for a webapplication but, I need lazy fetching without WebContent.

          is there a way to use this Interceptor inside a client application (yes the application runs inside tomcat but the beans they need lazy fetching are jobs that where fired by quartz) ?

          thanks.

          ys Gideon

          Comment

          Working...
          X