title: Getting "could not initialize proxy - no Session" despite the fact I'm using a @Transactional annotation
body: <p>I'm using Spring 3.1.1.RELEASE and Hibernate 4.1.0.Final.  I'm getting a "could not initialize proxy - no Session" exception, despite the fact I'm wrapping the relevant method call in a @Transactional annotation.  Here's my method …</p>
  
  <pre><code>@Service("teacherImportService")
  public class TeacherImportServiceImpl extends AbstractmyprojectService 
  {
      …
      @Transactional
      @Override
      public void saveUserObject(final JsonObject jsonData)  
      {
          …
          final myprojectOrganization myprojectOrg = myprojectOrgDao.findBymyprojectOrgId(myprojectSchoolId);
          final Organization school = myprojectOrg != null ? myprojectOrg.getOrg() : null;
              …
          final Address address = new Address();
          address.setState(school.getState());    // error occurs here
  </code></pre>
  
  <p>What else do I have to do to guarantee a transaction takes place?  I have included the "&lt;tx:annotation-driven /&gt;" in my application context, which I include below</p>
  
  <pre><code>&lt;context:component-scan base-package="org.mainco.subco" /&gt;
  ...
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="${test.mysql.dataSource.driverClassName}" /&gt;
      &lt;property name="url" value="${test.mysql.dataSource.url}" /&gt;
      &lt;property name="username" value="${test.mysql.db.user}" /&gt;
      &lt;property name="password" value="${test.mysql.db.password}" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="packagesToScan" value="org.mainco.subco" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/&gt;
      &lt;/property&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="jpaPropertyMap" ref="jpaPropertyMap" /&gt;
  &lt;/bean&gt;
  
  &lt;util:map id="jpaPropertyMap"&gt;
      &lt;entry key="hibernate.show_sql" value="true" /&gt;
      &lt;entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /&gt; 
      &lt;entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/&gt;
      &lt;entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/&gt;
      &lt;entry key="hibernate.cache.use_second_level_cache" value="true" /&gt;
      &lt;entry key="hibernate.cache.use_query_cache" value="false" /&gt;
      &lt;entry key="hibernate.generate_statistics" value="true" /&gt;
  &lt;/util:map&gt;
  
  &lt;bean id="sharedEntityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean"&gt;
     &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven /&gt;
  
  &lt;jdbc:initialize-database data-source="dataSource"&gt;
      &lt;jdbc:script location="classpath:truncate_tables.sql" /&gt;
      &lt;jdbc:script location="classpath:db-test-data.sql" /&gt;
  &lt;/jdbc:initialize-database&gt;
  </code></pre>
  
  <p>Here is full stack trace of the exception ...</p>
  
  <pre><code>org.hibernate.LazyInitializationException: could not initialize proxy - no Session
      at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
      at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
      at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
      at org.mainco.subco.organization.domain.Organization_$$_javassist_30.getState(Organization_$$_javassist_30.java)
      at org.mainco.subco.myproject.service.TeacherImportServiceImpl.saveUserObject(TeacherImportServiceImpl.java:101)
      at org.mainco.subco.myproject.service.AbstractmyprojectService.saveUsers(AbstractmyprojectService.java:226)
      at org.mainco.subco.myproject.service.AbstractmyprojectService$$FastClassByCGLIB$$d080e416.invoke(&lt;generated&gt;)
      at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
      at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
      at org.mainco.subco.myproject.service.TeacherImportServiceImpl$$EnhancerByCGLIB$$a06c7e9f.saveUsers(&lt;generated&gt;)
      at org.mainco.subco.myproject.service.TeacherImportServiceTest.testSaveTeachers(TeacherImportServiceTest.java:46)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>