今天在编写单表增删改查的时候,出现了问题:
后台的Action可以成功执行,也没有报错,但是数据库的数据就是没有修改!
运用的是HibernateDaoSupport中的方法
/**
 * 通过指定ID删除单条角色信息
 */
public void deleteRoleById(String roleId){
PtRoleInfo ptRoleInfo = (PtRoleInfo) this.getHibernateTemplate().get(PtRoleInfo.class, roleId);

this.getHibernateTemplate().delete(ptRoleInfo);
}
/**
 * 更改角色信息
 */
@SuppressWarnings("unchecked")
public void updateRoleInfoById(RoleInfo roleInfo){
//PtRoleInfo ptRoleInfo = new PtRoleInfo();这里New出来的对象,和数据库不能对应
PtRoleInfo ptRoleInfo = (PtRoleInfo) this.getHibernateTemplate().get(PtRoleInfo.class, roleInfo.getRoleId());

// ptRoleInfo.setRoleId(roleInfo.getRoleId());
ptRoleInfo.setRoleName(roleInfo.getRoleName());
ptRoleInfo.setDeil(roleInfo.getDeil());

this.getHibernateTemplate().update(ptRoleInfo);
}
/**
 * 保存角色信息
 */
public void saveRoleById(RoleInfo roleInfo){
PtRoleInfo ptRoleInfo = new PtRoleInfo();
ptRoleInfo.setRoleId(roleInfo.getRoleId());
ptRoleInfo.setRoleName(roleInfo.getRoleName());
ptRoleInfo.setDeil(roleInfo.getDeil());

this.getHibernateTemplate().save(ptRoleInfo);
}
我想可能是事物配置的问题<!-- 配置sessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
    </bean>    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    
    <!--配置事务的传播特性-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="modify*" propagation="REQUIRED" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>     <!-- 那些类的哪些方法参与事务 -->    <aop:config>
        <aop:advisor pointcut="execution(* com.test.dc.manager.*.*(..))"
            advice-ref="txAdvice" />
    </aop:config>
求教,到底哪里出了问题!谢谢了

解决方案 »

  1.   

    唉~~~什么配置我也不看了~~
    如果Action可以输出数据的话那么就是你的数据库的语言出问题了哈~~~
    检查一下你的语句哈~~~有时候少个字段什么错就不报,也可以在Action里输出
    也提示成功修改,但是就是不修改,这肯定就是你的数据库没有写正确哈~~~
    因为在数据库那里写错了是不会报错的~~~
      

  2.   

    <aop:config>
            <aop:advisor pointcut="execution(* com.test.dc.manager.*.*(..))"
                advice-ref="txAdvice" />
        </aop:config>
    你用这样吧:
    <aop:config>
        <aop:pointcut id="bizMethods"
      expression="execution(* com.test.dc.manager.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" />
    </aop:config>
      

  3.   

    我想应该也是 Spring事务配置有问题。  我以前也碰到过这问题,运行什么都是好的,无异常,就是数据没提交到数据库里面去,后来一检查是 pointcut里面写错了
      

  4.   

    现在关键的情况就是没有报异常哦!
    我也觉得是事物配置的问题,我对SPRING的事务管理不是很懂,还得再试试看了!
      

  5.   

    这个问题已经解决,原因可能是spring对于proxool连接配置不支持自动提交,必须在hibernate.cfg.xml中添加一个自动提交的配置:
    <property name="connection.autocommit">true </property>
    这样就能够写入数据库了
    代码没有问题,就是在缓存中没有做提交!
      

  6.   

    问题是解决了,但是不知道为什么会出现这样的错误,网上说是proxool的BUG,不太了解!
      

  7.   

    但是现在有个新的问题,之前的配置,我是把事务注释掉后调试的,而且通过了,可以进行增删改查!
    当我把事务管理添上去后就报错: <!-- 配置sessionFactory -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation">
                <value>classpath:hibernate.cfg.xml</value>
            </property>
        </bean>    <!-- 配置事务管理器 -->
        <bean id="transactionManager" 
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="sessionFactory">
                <ref bean="sessionFactory" />
            </property>    </bean>
        
        <!--  配置事务的传播特性 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="save*"/>
                <tx:method name="delete*"/>
                <tx:method name="update*"/>
                <tx:method name="*" read-only="true"/>
            </tx:attributes>
        </tx:advice>
        
        <!-- 哪些类的哪些方法参与事务 -->
        <aop:config>
            <aop:advisor pointcut="execution(* com.adtec.datacenter.dao..*(..))"
                advice-ref="txAdvice" />
        </aop:config>
    报错:
    [07:54:54] ERROR context.ContextLoader "Context initialization failed"
     org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dbUtilDao' defined in file [D:\Tomcat 5.5\webapps\DataCenter\WEB-INF\classes\applicationContext-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [D:\Tomcat 5.5\webapps\DataCenter\WEB-INF\classes\applicationContext-common.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [org.springframework.jdbc.datasource.DataSourceTransactionManager]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?是事务配置的问题?还是代码需要修改?
    为什么在没有注入事务管理的时候就不报错呢?
      

  8.   

    同上。 我也是这样。配置了OpenSessionInViewFilter ,sesson的提交就不是掌握在自己手上了。求高人帮助
      

  9.   

    恩 然后我就只能手动弄下 session.flush(); 这是它会立刻发出delete语句..