【发布时间】:2012-04-13 15:05:35
【问题描述】:
我有一个使用休眠连接到数据库并检索数据的方法。当作为独立的 java 应用程序执行时,该方法工作正常。但是,当我尝试将其部署在 tomcat 上并作为 Web 服务调用时,出现如下错误。我的方法是第一个也是唯一一个建立数据库连接的地方,即我没有在 tomcat 中定义任何数据源。
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>
我正在使用以下休眠模块:
hibernate-annotations 3.4.0.GA, 休眠核心 3.3.1.GA, 休眠 3.2.6.ga, hibernate-commons-annotations 3.1.0.GA
【问题讨论】:
-
您正在做什么来管理 Web 服务调用的 Hibernate 会话?
-
不确定我是否理解,但也许我应该:)。我正在使用spring并将数据源和会话工厂定义为spring bean。你问的是这个吗?