开发者社区> 问答> 正文

s2sh框架整合,hibernate无法执行删除问题

dao层的代码
public void deleteDepartment(Serializable id,String delMode) {
Department department=this.getDepartmentById(id);
//通过页面出来的参书id,获得 这个对象
if("del_pre_relation".equals(delMode)){
Set users = department.getUsers();
for(User user:users){
user.setDepartment(null);
}
}
this.getHibernateTemplate().delete(department);
}
action层的代码
public String deleteDepartment(){
this.departmentService.deleteDepartment(this.getModel().getDid(), "del");
return "action2action";
}
SessionFactory   的配置方式
<bean id="sessionFactory"   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation">
            <value>classpath:hibernate/hibernate.cfg.xml</value>
        </property>
    </bean>
    <bean id="transactionManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory"></ref>
        </property>
    </bean>
    <tx:advice id="tx"  transaction-manager="transactionManager">
     <tx:attributes>
        <tx:method name="save*"  read-only="false"/>
        <tx:method name="delete"  read-only="false" />
        <tx:method name="update*"  read-only="false"/>
        <tx:method name="get*"  read-only="true"/>
     </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut expression="execution(* cn.service.impl.*.*(..))"  id="perform"/>
        <aop:advisor advice-ref="tx"  pointcut-ref="perform"/>
    </aop:config>
hibernate.cfg.xml

jdbc:mysql://localhost:3306/test
com.mysql.jdbc.Driver
root
1111
50
<!-- 配置C3p0连接池 -->
<!-- 启用c3p0连接池 设置连接池提供的供应商 --> 
org.hibernate.connection.C3P0ConnectionProvider
<!-- 最大连接数 -->
20
<!-- 最小连接数 -->
5
<!-- 每次请求连接的数目 -->
5
<!-- 设置过期时间,以秒为单位,如果连接池中 -处于空闲状态的连接超过了这个时间,该连接就会从连接池中删除-->
120
<!-- 每个3000秒检查连接池中的空闲连接 -->
3000
<!-- 设置隔离级别  1 2 4  8-->
<property name="connection.isolation">2</property>

<!-- 配置session的线程本地化 threadLocal -->
<property name="current_session_context_class">thread</property>

<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>

<mapping resource="cn/domain/hibernate-user.xml"/>          
<mapping resource="cn/domain/hibernate-department.xml"/>            
<mapping resource="cn/domain/hibernate-post.xml"/>          

可是就是执行不了,debug了Dao层的delete方法,也都是执行了的,求教大神是怎么回事

展开
收起
云栖技术 2016-06-02 15:31:34 2102 0
1 条回答
写回答
取消 提交回答
  • 社区爱好者,专为云栖社区服务!

    你这里的delete后边少了“*”号

         <tx:attributes>
                        <tx:method name="save*"  read-only="false"/>
                        <tx:method name="delete"  read-only="false" />
                        <tx:method name="update*"  read-only="false"/>
                        <tx:method name="get*"  read-only="true"/>
    2019-07-17 19:25:02
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载