我正在更新我的應用程序到Spring 3.2.5和Hibernate 4.2.7。一切都再編譯,但是當我運行該應用程序我得到:錯誤沒有會話綁定到Hibernate 4和Spring 3的當前線程
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:990)
at com.traficon.tmsng.server.common.sequence.SequenceGeneratorServiceImpl$EventIdInitializer.doInitialize_aroundBody0(SequenceGeneratorServiceImpl.java:182)
at com.traficon.tmsng.server.common.sequence.SequenceGeneratorServiceImpl$EventIdInitializer$AjcClosure1.run(SequenceGeneratorServiceImpl.java:1)
at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96cproceed(AbstractTransactionAspect.aj:59)
at org.springframework.transaction.aspectj.AbstractTransactionAspect$AbstractTransactionAspect$1.proceedWithInvocation(AbstractTransactionAspect.aj:65)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:63)
at com.traficon.tmsng.server.common.sequence.SequenceGeneratorServiceImpl$EventIdInitializer.doInitialize(SequenceGeneratorServiceImpl.java:179)
at com.traficon.tmsng.server.common.cache.initializer.BaseCoherenceInitializer.initializeIfNeeded(BaseCoherenceInitializer.java:236)
at com.traficon.tmsng.server.common.cache.initializer.BaseCoherenceInitializer.getCache(BaseCoherenceInitializer.java:98)
at com.traficon.tmsng.server.common.sequence.SequenceGeneratorServiceImpl.getHighestEventId(SequenceGeneratorServiceImpl.java:120)
at com.traficon.tmsng.server.common.sequence.SequenceGeneratorServiceImpl.access$0(SequenceGeneratorServiceImpl.java:118)
at com.traficon.tmsng.server.common.sequence.SequenceGeneratorServiceImpl$SequenceGeneratorInitializer.run(SequenceGeneratorServiceImpl.java:149)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
你如果透過堆棧跟蹤,你看到交易方面,所以我認爲是好的。
我有這個在我的應用程序上下文:
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
我的SessionFactory的是org.springframework.orm.hibernate4.LocalSessionFactoryBean
。
我已設置:
任何想法可能是錯誤的?
UPDATE:
看來只有方法標註有@Transactional(Propagation.SUPPORTS)
和@Transactional(Propagation.NEVER)
不工作。如果我將它們更改爲Propagation.REQUIRED
,那麼它可以工作。但爲什麼?這個在Spring 3.0.4和Hibernate 3.5.6中用得很好。
你啓用和/或更新您的OpenSessionInViewFilter? –
我從來不需要一個。我直接使用ClassPathXmlApplicationContext,它不是一個web應用程序。 –