我使用hibernateTemplate保存数据:
UserDaoImpl:public User add(User user) {
System.out.println("保存前");
Integer uid = (Integer) this.getHibernateTemplate().save(user);
System.out.println("保存后");
user.setUid(uid);
return user;
}UserService:public User add(User user) {
user=userDao.add(user);
return user;
}test:@Test
public void testSave() {
User user = new User();
user.setUsername("小胡");
user.setPassword("xiaoHu");
userService.add(user);
System.out.println("user.uid:" + user.getUid());
}我在UserDaoImpl里有HibenateTemplate字段及其get和 set方法我的bean.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:context="http://www.springframework.org/schema/context"
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-2.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
              http://www.springframework.org/schema/tx 
              http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com"></context:component-scan>
<!--jdbc.properties -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<!-- 配置DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 最大 连接数 -->
        <property name="maxActive" value="100"></property>
        <!--最大空闲连接 -->
        <property name="maxIdle" value="30"></property>
        <!-- 最大等待连接 -->
        <property name="maxWait" value="500"></property>
        <!-- 默认最大提交,TRUE,每操作一次数据库自动提交 
        <property name="defaultAutoCommit" value="true"></property>-->
</bean>
<!--配置hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
<!--  <prop key="hibernate.current_session_context_class">jta</prop>-->
<!--
<prop key="hibernate.current_session_context_class">thread</prop>
-->
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.model</value>
</list>
</property>
</bean>
<!-- hibernateTemplate -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!--事务
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>-->
<!--<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="select*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut id="anyMethod"
expression="execution(public * com.service..*.*(..))" />
<aop:advisor pointcut-ref="anyMethod" advice-ref="txAdvice" />
</aop:config> -->
</beans>我试验保存方法,可是总是执行不完,这是为什么呢?
还有,我把事务的代码不注解,能执行完保存,但是不提交,也执行不完
都到现在了,按钮还是红色的状态,这是为什么呀我在线等,求调用!!!!