Announcement Announcement Module
Collapse
No announcement yet.
dm Server 2.0 and Hibernate Lazy Loading Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • dm Server 2.0 and Hibernate Lazy Loading

    I'm setup so that my web bundle imports @transactional services from a service bundle and a hibernate service factory from a dao bundle. I then use the reference to the servicefactory in an "Open Session in View" filter, and that allows me to access lazily loaded objects in my view. This all worked well in dm Server 1.x, but in dm Server 2.0 I'm getting

    failed to lazily initialize a collection of role: com.spintop.domain.PublisherImpl.hiberContractTerm sSet, no session or session was closed org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.spintop.domain.PublisherImpl.hiberContractTerm sSet, no session or session was closed

    I'm not even sure which bundle to be looking for problem in.

    Thank you.

  • #2
    After looking a little deeper into the problem, I suspect it has something to do with how Spring ORM discovers sessionholders that are bound to the thread. Stepping through TransactionSynchronizationManager.doGetResource(Ob ject actualKey) shows that the actualKey is a SessionFactoryImpl while the key that's stored in the map is a Proxy that points to the same SessionFactoryImpl.

    Comment


    • #3
      Okay, think I've tracked it down. In Spring 3.0's TransactionSynchronizationUtils.unwrapResourceIfNe cessary() method

      Code:
      static Object unwrapResourceIfNecessary(Object resource) {
      		Assert.notNull(resource, "Resource must not be null");
      		Object resourceRef = resource;
      		// unwrap infrastructure proxy
      		if (resourceRef instanceof InfrastructureProxy) {
      			resourceRef = ((InfrastructureProxy) resourceRef).getWrappedObject();
      		}
      		if (aopAvailable) {
      			// now unwrap scoped proxy
      			resourceRef = ScopedProxyUnwrapper.unwrapIfNecessary(resource);
      		}
      		return resourceRef;
      	}
      It's unwrapping the Proxy (InfrastructureProxy), but then if AOP is available, it calls ScopedProxyUnwrapper.unwrapIfNecessary(resource) on the original Proxy and because it's not a ScopedObject, it's overwriting the unwrapped object with the original proxy.

      Edit: I see there is already a JIRA open for this: http://jira.springframework.org/browse/SPR-6625

      Thank you.
      Last edited by kierann; Jan 27th, 2010, 03:47 PM.

      Comment


      • #4
        I tried using the latest nightly build of spring to get around this, but dm server will not start with spring 3.0.1.CI-xxx in its repository. Something about package conflicts.

        Comment


        • #5
          Working great now with Spring 3.0.2

          Comment

          Working...
          X