Announcement Announcement Module
Collapse
No announcement yet.
LaxyInitialization Error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LaxyInitialization Error

    Hi,
    I am new to Hibernate and Spring. I am getting the lazyInitialization error in my application. I am using struts2 with hibernate and spring. This seems to be a common problem and I found many posts on it. But I am unable to find a common solution for this problem.

    I tried referring the 'OpenSessionInViewFilter' in my web.xml.
    <filter>
    <filter-name>lazyLoadingFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.O penSessionInViewFilter</filter-class>
    </filter>

    Now I am getting another error
    'No bean named 'sessionFactory' is defined'.

    This is because I have two 'applicationContext-dao-.xml' files with beans sessionFactoryMediware and sessionFactoryClinical defined in them. I need to use these two beans separately. So I dont have the sessionFactory bean defined. This results in the above mentioned error.
    Is there any other way to solve the lazy initialization problem?

    Any help would be greatly appreciated.

    Thanks & Regards
    Ajay

  • #2
    You can specify which SessionFactory to use (check the javadocs for the OpenSessionInViewFilter) however that still wouldn't solve your problem as you are working with 2 sessionfactories. Do you really need 2 sessionfactories, you only would need them if you would be working with a completly different database, if it is the same database you could work with one.

    However your problem is a bit more complicated.

    Comment


    • #3
      LazyInitialization Multiple SessionFactories

      Hi,
      Yes I do need two sessionFactories since I need to access two databases in my application (Mediware and Clinical). Is there a way to solve this problem? Any pointers would be very helpful. I am stuck with this for the past 2-3 weeks.

      Thanks & Regards
      Ajay

      Comment


      • #4
        The easiest solution is to make sure that you pre-fetch all the stuff you need in your view. However that would require you to modify your service/data access layer. Because you then need to know what to retrieve.

        Comment


        • #5
          Hi,
          I tried specifying the session factory in web.xml as given below
          <filter>
          <filter-name>lazyLoadingFilter</filter-name>
          <filter-class>org.springframework.orm.hibernate3.support.O penSessionInViewFilter</filter-class>
          <init-param>
          <param-name>sessionFactoryBeanName</param-name>
          <param-value>sessionFactoryMediware</param-value>
          </init-param>
          </filter>

          Now I get the following error, when I try to save any record in any table.

          Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

          I have not set any mode as 'Read Only'. Due to the change I did in web.xml this error is now occuring.
          Any idea on this would be very helpful.

          Thanks & Regards
          Ajay

          Comment


          • #6
            Hi all,
            I am also facing the same 'Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL' problem. Initially there was no such errror. Then I added 'OpenSessionInViewFilter' in web.xml to fix the lazyinitialization problem that was coming. Now this problem has cropped up.
            Any idea on this issue will be greatly appreciated.

            Thanks
            Ajay

            Comment

            Working...
            X