日期:2014-05-20  浏览次数:20825 次

spring3整合hibernate使用XML配置事务处理时总报错,请高手进来看看。
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/tx 
  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
  http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 

<context:component-scan base-package="com.shrx" /> 

  <context:annotation-config /> 
   

<aop:config> 
<aop:pointcut id="bussinessService" 
expression="execution(public * com.shrx.service..*.*(..))" /> 
<aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" /> 
</aop:config> 
<tx:advice id="txAdvice" transaction-manager="txManager"> 

<tx:attributes> 

<tx:method name="add*" /> 
</tx:attributes> 
</tx:advice> 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
destroy-method="close"> 
<property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
<property name="url" value="jdbc:mysql://localhost:3306/spring" /> 
<property name="username" value="root" /> 
<property name="password" value="zhaoxin" /> 
</bean> 

<bean id="sf" 
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
<property name="dataSource" ref="dataSource" /> 
<property name="annotatedClasses"> 
<list> 
<value>com.shrx.model.User</value> 
</list> 
</property> 
<property name="hibernateProperties"> 
<props> 
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
<prop key="heibernat.show_sql">true</prop> 

</props> 

</property> 

</bean> 

<bean id="u" class="com.shrx.dao.impl.UserDAOImpl"></bean> 
<bean id="user" class="com.shrx.model.User"></bean> 
<bean id="userService" class="com.shrx.service.UserService"></bean> 
<bean id="txManager" 
class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
<property name="sessionFactory" ref="sf" /> 
</bean> 

</beans> 


package com.shrx.dao.impl; 


import java.sql.Connection; 
import java.sql.SQLException
import java.sql.Statement; 

import javax.annotation.Resource; 
import javax.sql.DataSource; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory;