Announcement Announcement Module
No announcement yet.
Context or session available after loading with struts plugin Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Context or session available after loading with struts plugin


    Here is my problem:

    I'm using Spring, Hibernate3, struts1.1. I used the plugin for struts so the application context is being created and I can use the injection.

    Now I have to create this tag library and I need to wire some of the beans that I use there.

    So, since this are not "connected" with the struts actions etc, I don't have a existing context. What I was trying to do is something like

    Resource res = new FileSystemResource("C:/apps/Tomcat5.5/webapps/myApp/WEB-INF/applicationContext.xml");
    		factory = new XmlBeanFactory(res);
    And that loads the context but I get this exception:

    [13 Apr 2006 13:08:30,083 LazyInitializationException(line:19) ERROR] could not initialize proxy - the owning Session was closed
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
    	at org.hibernate.proxy.AbstractLazyInitializer.initialize(
    	at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(
    	at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.intercept(
    	at com.dropshopz.model.Rate$$EnhancerByCGLIB$$23265776_2.getIdAsString(<generated>)

    I believe it's because I already had the other session.

    So what I what to know is: is there any way to get the context created with the struts plugin?

    I mean do something like:

    Context ctx =(Context)request.getAttribute("spring.struts.cont ext);

    So I can gen my beans like MyManager m = (MyManager)ctx.getBean("myManager");

    Please remember that I'm doing this from a tag library

    Any Help is greatly appreciated

  • #2
    To get access to the WebApplicationContext you can use the following util:

    Nevertheless your problem seems to be related to the Hibernate Session. You might have loaded a Hibernate object in one Hibernate Session and you try to access it in an other Hibernate Session.

    This usually happens if you load a Hibernate object in one request, store it in the Servlet Session and access it in an other Servlet Session.
    Or maybe your Hibernate Session is closed in your service layer und you try to access lazy loded Hibernate objects in your view? The you might have a look at:

    BTW: I call the objects that are managed by Hibernate "Hibernate objects"