我就像做个shh 存储输入的信息到数据库然后显示succss   新人 对事务还是不太明白
网上说的方法也加了 实在是不会弄了 求大神指点

求助 下面发我源代码
applicationContext.xml错误信息dao层
javaeesshhibernate

解决方案 »

  1.   

    在web.xml中配置
    <!-- openSessionInView配置 -->
    <filter>
    <filter-name>openSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>openSessionInViewFilter</filter-name>
    <url-pattern>*.action</url-pattern>
    </filter-mapping>
      

  2.   

    额 再弱弱的问一句 不加事务行不行?我再applicationcontext.xml文件没加事务 事务是干嘛用的
    currentsession()里面有事务吗 session再dao中用关吗?
      

  3.   

    我以前试过 不好用 刚才安你的说法又clean 重新run 还是这个界面。。
      

  4.   

    如果使用openSession方法获取Session可以么?
      

  5.   

    额 opensession似乎不好 别人给的建议是用currentsession 我就尝试
      

  6.   

    如果想事务起作用好像必须得用currentSession
      

  7.   

     对事务不太懂 这个程序就卡这了 新手我研究两周ssh了  估计这是最后一步把。。
      

  8.   

    在spring里配置上事物就可以了。
      

  9.   


    <bean id="transactionManager" 
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
            <property name="sessionFactory" ref="sessionFactory"></property>  
        </bean> 
        <tx:advice id = "txAdice" transaction-manager="transactionManager">
         <tx:attributes>
         <tx:method name="insert*" propagation="REQUIRED" />  
                <tx:method name="update*" propagation="REQUIRED" />  
                <tx:method name="delete*" propagation="REQUIRED" />  
                <tx:method name="get*" propagation="REQUIRED" read-only="true"/>  
                <tx:method name="query*" propagation="REQUIRED" read-only="true"/>  
                <tx:method name="*" propagation="REQUIRED" read-only="true" />
         </tx:attributes>
        </tx:advice>
        <aop:config>
         <aop:pointcut id="pointCut" expression="execution(* com.test..service.impl.*.*(..))" />
         <aop:advisor pointcut-ref="pointCut" advice-ref="txAdice"/>
        </aop:config>
      

  10.   


    /**
     * Copyright (C) 2012  http://blog.csdn.net/Just_szl
     * 
     * 修订历史记录:
     * 
     * Revision 1.0 2012-11-15 Geray  创建。
     * 
     */
    package com.hibernate.util;import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.Session;/**
     * 
     * @author <a href="mailto:[email protected]"> Geray</a>
     * @version 1.0,2012-11-15 
     */
    public class HibernateUtil {

    private static SessionFactory sessionFactory;

    private static Configuration configuration;

    static
    {
    try {
    configuration = new Configuration().configure();
    sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
    e.printStackTrace();
    }

    }

    public static Configuration getConfiguration(){
    return configuration;
    }

    public static Session openSession(){
    return sessionFactory.openSession();
    }

    public static void closeSession(Session session){
    if(null != session){
    session.close();
    }
    }}写过这么一个得到Session的工具类,你可以试一下,当然当你打开一个Session之后必须调用closeSession方法关闭Session
      

  11.   

    那么在做javaee企业开发时候 有多个session时候  opensession 再closesession 岂不是很麻烦? 就没有什么好方法去更好得操控session?
      

  12.   

    对于Spring添加事物管理后,貌似是不需要手动关闭Session的。