在save外面加一个try catch,把错误打印出来看一下。以前也碰到过,没有捕获的话不会报异常,然后就是不能插入到数据库。
你试一下是不是这个原因。或者设置断点,调试一下,看一下执行save的时候有没有报错误。

解决方案 »

  1.   

    有无事务?service层那个方法要不要加事务?
      

  2.   

       既然用注解,把
        <bean id="transactionInterceptor"
            class="org.springframework.transaction.interceptor.TransactionInterceptor">
            <property name="transactionManager" ref="transactionManager"></property>
            <property name="transactionAttributes">
                <props>
                    <prop key="save*">PROPAGATION_REQUIRED</prop>
                    <prop key="update*">PROPAGATION_REQUIRED</prop>
                    <prop key="delete*">PROPAGATION_REQUIRED</prop>
                    <prop key="find*">PROPAGATION_REQUIRED</prop>
                    <prop key="get*">PROPAGATION_REQUIRED</prop>
                    <prop key="execute*">PROPAGATION_REQUIRED</prop>
                    <prop key="load*">PROPAGATION_REQUIRED</prop>
                    <prop key="merge*">PROPAGATION_REQUIRED</prop>
                    <prop key="add*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
        </bean>
    改为
     <!-- 注入事务 -->
        <tx:annotation-driven transaction-manager="transactionManager" />再加入
    <!-- 自动扫描 bean -->
    <context:annotation-config />
    <context:component-scan base-package="zzz.xxx"/>service上加@Transactional@Transactional
    @Service("teacherService")
    public class TeacherService {
      
      

  3.   

    多半是事务引起的,我用的是aop你试试看我的代码<context:component-scan base-package="com.share.service.*">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
    </context:component-scan>
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean> <tx:annotation-driven proxy-target-class="true" />
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
    <tx:method name="get*" read-only="true" propagation="REQUIRED" />
    <tx:method name="search*" read-only="true" propagation="REQUIRED" />
    <tx:method name="isExist*" read-only="true" propagation="REQUIRED" />
    <tx:method name="load*" read-only="true" propagation="REQUIRED"/>
    <tx:method name="*" propagation="REQUIRED" />
    </tx:attributes>
    </tx:advice> <aop:config>
    <aop:pointcut expression="execution(public * com.share.service..*.*(..))"
    id="bussinessService" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="bussinessService" />
    </aop:config>
      

  4.   

    还是别用这种方式控制事务了,spring这块有严重问题,对同一个表读写频繁很容易锁死数据源。
      

  5.   

    我用session.flush()就没有问题了。
      

  6.   

    楼主,我和你一样的问题,只有save方法不起作用,后面要跟上flush方法才起效,楼主怎么解决的?
      

  7.   

    我的也是这问题,事务控制应该没问题,因为修改和删除都正常,就只有这个save没效果,增加了flush后竟然还报错了,但是hibernate往数据库插入数据的语句显示出来了,但数据库还是没数据
      

  8.   

    问一下这里只是扫描了
    <context:component-scan base-package="com.share.service.*">
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/>
        </context:component-scan>
    的注解,其他注解配置在哪里配