Announcement Announcement Module
Collapse
No announcement yet.
How to get associated objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get associated objects

    hello, i am experiencing a problem with my site. Hopefully this forum can help.

    Code:
    xception
    
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:408)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    
    root cause
    
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
    	org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
    	org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
    	com.mofo.Domain.Account.User$$EnhancerByCGLIB$$3a5fc610.getUserName(<generated>)
    	com.mofo.Controller.LoginHomePageController.referenceData(LoginHomePageController.java:53)
    	org.springframework.web.servlet.mvc.SimpleFormController.referenceData(SimpleFormController.java:209)
    	org.springframework.web.servlet.mvc.AbstractFormController.showForm(AbstractFormController.java:557)
    	org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:193)
    	org.springframework.web.servlet.mvc.SimpleFormController.showForm(SimpleFormController.java:172)
    	org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:323)
    	org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:263)
    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:806)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:736)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

    What i think the problem is, is best explained through an example.
    public class foo {
    int id;
    Bar bar;
    }

    public class Bar{

    }

    given two classes, when i perform a findAll(foo) on objects of type foo, it loads and returns a list fine, however whenever i reference foo.bar i get an error. how can i load all the associated objects with a given class. I am sure there is something in the mapping that handles that. Any suggestions.
    Herei s the mapping.

    Code:
    <hibernate-mapping>
    
        <class name="com.lbm.Domain.System.Con" table="con">
            <id name="ID" column="ID">
                <generator class="assigned" />
            </id>
            <property name="post" type="text" />
            <many-to-one name="user" column="user_id" class="com.mofo.Domain.Account.User" cascade="all"/>  
            <property name="dateCreated" type="date" column="dateCreated"/>
            <property name="lastModifiedOn" type="date" column="lastModifiedOn"/>
            <property name="deleted" type="boolean" column="deleted"/>
        </class>
        
    </hibernate-mapping>
    Last edited by netvampire; Nov 1st, 2007, 11:21 PM.

  • #2
    Originally posted by netvampire View Post
    I am sure there is something in the mapping that handles that.
    There are actually very many ways to handle it. Eager loading by setting the relationship to lazy="false", by fetching the related objects with the actual data, using OSIV and so on.
    Usually, when it is a 1:n as in your case with bar:foo I used the lazy="false" approach in the Hibernate mapping. Have a look into the Hibernate reference for the details.

    Joerg

    Comment


    • #3
      thanks. lazy did the trick.

      Comment

      Working...
      X