Announcement Announcement Module
Collapse
No announcement yet.
org.hibernate.LazyInitializationException Again and Please Help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.hibernate.LazyInitializationException Again and Please Help

    Hi All

    I am just learning about spring + hibernate on normal application (Swing) everything run smoothly until lazyloading problem
    here is the error
    3703 [main] ERROR org.hibernate.LazyInitializationException - failed to lazily initialize a collection of role: com.jimmy.quoteonline.pojo.Division.categories - no session or session was closed

    now i have trying to change my applicationContext.xml

    now like this

    <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.Hibernat eInterceptor">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="maintenanceServiceTarget" class="com.acompany.MaintenanceServiceImpl">
    <property name="categoryDao"><ref bean="categoryDao" /></property>
    <property name="divisionDao"><ref bean="divisionDao" /></property>
    </bean>
    <bean id="maintenanceService" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="target">
    <ref bean="maintenanceServiceTarget" />
    </property>
    <property name="proxyInterfaces">
    <value>com.acompany.MaintenanceService</value>
    </property>
    <property name="interceptorNames">
    <list>
    <value>hibernateInterceptor</value>
    </list>
    </property>
    </bean>

    is anyone can please please help me?

    Spring + Hibernate should be extremely easy but with this lazy it is throwing more trouble that it should be

    please help

    many thanks in advance

  • #2
    Lazy loading is really an ORM issue rather than a Spring issue. Yes, it is one of the trickier challenges when using any ORM product.

    I suggest the following choices of options:

    1. Eagerly load the relationship in your Hibernate mappings. (Probably not the best performing option); OR
    2. Use a fetch join to retrieve the data eagerly for your use case (modify HQL or use a Criteria query); OR
    3. "Touch" the associated data within your service layer before data is returned to the web tier outside a transaction to ensure it's materialized; OR
    4. Use the Open Session in View approach, with Spring's Open Session in View Filter or HandlerInterceptor. This will allow lazy-loaded data still to be retrieved in the web tier, even after the transaction has been closed.

    Comment

    Working...
    X