Exception in thread "main" org.hibernate.HibernateException: createQuery is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at $Proxy5.createQuery(Unknown Source)
at com.wz.dao.basic.BasicDao.executeQuery(BasicDao.java:39)
at com.wz.test.Test.main(Test.java:22)
applicationContext.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>



<bean id="userDaoImpl" class="com.wz.dao.impl.UserDaoImpl">

<property name="sessionFactory" ref="sessionFactory"/>
</bean>
 
 <!-- 配置Hibernate的局部事物管理器 -->
     <bean id="transactionManager"
             class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
         <ref local="sessionFactory" />
        </property>
    </bean>
    
     <!-- 配置事物切面Bean -->
     <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" />
        </tx:attributes>
      </tx:advice>
      <!-- 配置一个切入点,匹配指定包下所有以Impl结尾的类 -->
      <!-- 由于Spring注入的是接口,关联的是实现类。在Spring的配置文件加上下面代码,注明可以用实现类注入    <aop:config proxy-target-class=“true”></aop:config>   -->
      <aop:config proxy-target-class="true">
      <aop:advisor
pointcut="execution(* com.wz.dao.impl.*Impl.*(..))"
advice-ref="txAdvice" />
      </aop:config>
</beans>执行方法代码 public List executeQuery(String hql, Object[] parameters) {

// Transaction ts=this.sessionFactory.getCurrentSession().beginTransaction();

HibernateTemplate hibernateTemplate =
new HibernateTemplate(this.sessionFactory);


Query query=hibernateTemplate.getSessionFactory().getCurrentSession().createQuery(hql); //注入?值
if(parameters!=null && parameters.length>0){
for(int i=0;i<parameters.length;i++){
query.setParameter(i, parameters[i]);

}
}
List list=query.list();
// ts.commit();
return list;
}
hibernatespring