此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【wnhoo】截止到2008-07-17 13:18:54的历史汇总数据(不包括此帖):
发帖的总数量:4                        发帖的总分数:400                      每贴平均分数:100                      
回帖的总数量:7                        得分贴总数量:3                        回帖的得分率:42%                      
结贴的总数量:4                        结贴的总分数:400                      
无满意结贴数:0                        无满意结贴分:0                        
未结的帖子数:0                        未结的总分数:0                        
结贴的百分比:100.00%               结分的百分比:100.00%                  
无满意结贴率:0.00  %               无满意结分率:0.00  %                  
敬礼!

解决方案 »

  1.   

    为什么不用getHibernateTemplate().save();
      

  2.   

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="configLocation"
    value="file:src/hibernate.cfg.xml">
    </property>
    </bean>
    <bean id="GuestbookDAO" class="com.oneic.hibernate.GuestbookDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <!--加入事务部分-->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <tx:advice id="txAdvice">
    <!-- the transactional semantics... -->
    <tx:attributes>
    <!-- all methods starting with 'get' are read-only -->
    <tx:method name="save*" />
    <tx:method name="delete*" />
    <tx:method name="add*" />
    <tx:method name="*" propagation="REQUIRED" read-only="true" />
    <!-- other methods use the default transaction settings (see below) -->
    <tx:method name="*" />
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="fooServiceOperation"
    expression="execution(* com.xxx.dao.*.*(..))" />
    <aop:advisor advice-ref="txAdvice"
    pointcut-ref="fooServiceOperation" />
    </aop:config></beans>
    别忘了expression="execution(* com.xxx.dao.*.*(..))" />改成你自己的dao的包
      

  3.   


    对阿,用spring整合hibernate了,为什么手动操作session?
      

  4.   

    加上
    <bean id="hibernateInterceptor"
    class="org.springframework.orm.hibernate3.HibernateInterceptor">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <!-- 表示允许自动提交 -->
    <prop key="hibernate.connection.autocommit">true</prop>
    <!-- 显示sql语句 -->
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
      

  5.   

    感谢,Landor2004 !但是 <tx:advice id="txAdvice">
            <!-- the transactional semantics... -->
            <tx:attributes>
                <!-- all methods starting with 'get' are read-only -->
                <tx:method name="save*" />
                <tx:method name="delete*" />
                <tx:method name="add*" />
                <tx:method name="*" propagation="REQUIRED" read-only="true" />
                <!-- other methods use the default transaction settings (see below) -->
                <tx:method name="*" />
            </tx:attributes>
        </tx:advice>
        <aop:config>
            <aop:pointcut id="fooServiceOperation"
                expression="execution(* com.xxx.dao.*.*(..))" />
            <aop:advisor advice-ref="txAdvice"
                pointcut-ref="fooServiceOperation" />
        </aop:config>
    这部分具体什么意思能否给解释一下!
      

  6.   

    <!-- 表示允许自动提交 --> 
    <prop key="hibernate.connection.autocommit">true </prop> 这个方式也是可以,不过这个和用Spring事务有什么区别了,在性能上是否有差别,还是其他什么原因!
      

  7.   

    这里面用到了spring2的AspectJ表示法,楼主可以看看spring的中文帮助,
    意思就是说符合* com.xxx.dao.*.*(..)表达式的类的save*、delete*等方法会被transactionManager管理,也就是加上事务* com.xxx.dao.*.*(..)也是AspectJ表达式
      

  8.   

    我想可能是没有commit吧.......你insert了以后没有commit建议拿getHiberanteTemplate来用,它会帮你做一些事情..
    我想可能是没有commit吧.......你insert了以后没有commit建议拿getHiberanteTemplate来用,它会帮你做一些事情..