我得到了一種使用hibernate連接到數據庫並檢索數據的方法。該方法作爲獨立的Java應用程序執行時工作正常。但是,當我嘗試將它部署在tomcat上並作爲Web服務調用時,我收到如下錯誤。我的方法是建立數據庫連接的第一個也是唯一的地方,即我沒有在tomcat中定義任何數據源。當通過Web服務調用時,Hibernate不起作用
No Hibernate Session bound to thread, and configuration does not allow creation
of non-transactional one here
at
org.springframework.orm.hibernate3.LocalSessionFactoryBean$TransactionAwareInvocationHandler.invoke(LocalSessionFactoryBean.
我的休眠配置文件:
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="exposeTransactionAwareSessionFactory" value="true" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
<prop key="hibernate.statement_cache.size">10</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.default_schema">${mydbSchema}</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
</props>
</property>
</bean>
我用下面的休眠模塊:
休眠批註3.4.0.GA, 休眠核心3.3.1.GA , hibernate 3.2.6.ga, hibernate-commons-annotations 3.1.0.GA
你在做什麼來管理Web服務調用的Hibernate會話? – MarkOfHall 2012-04-13 16:27:04
不知道我明白,但也許我應該:)。我正在使用spring,並將數據源和會話工廠定義爲spring beans。這是你在問什麼? – 2012-04-13 19:32:52