获得;HibernateException:没有绑定到线程的Hibernate会话,&;配置不';“我不允许创造……”;执行spring休眠时
我正试图编写一个简单的SpringHibernate命令行应用程序,它支持事务管理,但我不断地得到支持 “org.hibernate.HibernateException:没有绑定到线程的hibernate会话,并且配置不允许在此创建非事务会话” 我的spring配置文件(applicationContext.xml) 我使用的是hibernate版本3.1.3和Spring3。 如何为每个线程配置一个会话?我认为问题在于没有会话与我的执行线程相关联。我假设事务管理器将打开一个尚未找到的会话,但它不会这样做 引用1: 我使用的是hibernate版本3.1.3和Spring3 引文2: 注意获得;HibernateException:没有绑定到线程的Hibernate会话,&;配置不';“我不允许创造……”;执行spring休眠时,hibernate,spring,command-line,Hibernate,Spring,Command Line,我正试图编写一个简单的SpringHibernate命令行应用程序,它支持事务管理,但我不断地得到支持 “org.hibernate.HibernateException:没有绑定到线程的hibernate会话,并且配置不允许在此创建非事务会话” 我的spring配置文件(applicationContext.xml) 我使用的是hibernate版本3.1.3和Spring3。 如何为每个线程配置一个会话?我认为问题在于没有会话与我的执行线程相关联。我假设事务管理器将打开一个尚未找到的会话,但
从Spring3.0开始,Spring需要Hibernate3.2或更高版本 ()
顺便说一句,谢谢。。。我将试用最新版本。
<!-- Context Provider -->
<bean class="com.rps.util.ContextUtil" />
<!-- The transactional service objects -->
<bean id="service" class="com.rps.service.DefaultService" p:parentDao-ref="parentDao" p:childDao-ref="childDao" />
<!--the transactional advice-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!--this transactional advice runs for any service method execution-->
<aop:config>
<aop:advisor pointcut="execution(* com.rps.service..*.*(..))" advice-ref="txAdvice" />
</aop:config>
<!-- The PlatformTransactionManager -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" />
<!-- The DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3306/OsivTest" p:username="XXX" p:password="YYY" />
<!-- Session Factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" p:dataSource-ref="dataSource">
<property name="mappingResources">
<list>
<value>com/rps/domain/Parent.hbm.xml</value>
<value>com/rps/domain/Child.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Data Access Objects -->
<bean id="parentDao" class="com.rps.data.hbm.HibernateParentDao" p:sessionFactory-ref="sessionFactory" />
<bean id="childDao" class="com.rps.data.hbm.HibernateChildDao" p:sessionFactory-ref="sessionFactory" />
public List<T> findAll() {
return sessionFactory.getCurrentSession().createCriteria(getPersistentClass()).list();
}
public class DefaultService implements Service {
@Override
public List<Parent> getAllParent() {
return parentDao.findAll();
}
//Other methods
}
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Service s = (Service) context.getBean("service");
s.getAllParent();
}