J2EE社区

苟有恒,何必三更起五更眠;
最无益,只怕一日曝十日寒.
posts - 241, comments - 318, trackbacks - 0, articles - 16
796 INFO [com.opensymphony.xwork2.validator.ActionValidatorManagerFactory] - Detected AnnotationActionValidatorManager, initializing it...
Hibernate:
    select
        sysaccount0_.Account_ID as Account1_14_,
        sysaccount0_.Account_Model as Account2_14_,
        sysaccount0_.Account_Name as Account3_14_,
        sysaccount0_.Account_Pwd as Account4_14_,
        sysaccount0_.Account_Des as Account5_14_,
        sysaccount0_.WO_ID as WO6_14_
    from
        dbo.Sys_Account sysaccount0_
    where
        sysaccount0_.Account_Name=?
        and sysaccount0_.Account_Pwd=?
2009-11-22 01:51:52,859 ERROR [org.hibernate.LazyInitializationException] - could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
 at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
 at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
 at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
 at cn.edu.cuit.disasterSystem.business.pojo.SysWeatherOrg_$$_javassist_0.getWeatherOrgName(SysWeatherOrg_$$_javassist_0.java)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
 at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
 at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
 at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
 at org.apache.jsp.jsp.frame.top_jsp._jspService(top_jsp.java:241)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at cn.edu.cuit.disasterSystem.web.filter.SessionInalidateFilter.doFilter(SessionInalidateFilter.java:54)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at cn.edu.cuit.disasterSystem.web.filter.SecurityValidateFilter.doFilter(SecurityValidateFilter.java:43)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
 at java.lang.Thread.run(Thread.java:619)
2009-11-22 1:51:52 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
 at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
 at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
 at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
 at cn.edu.cuit.disasterSystem.business.pojo.SysWeatherOrg_$$_javassist_0.getWeatherOrgName(SysWeatherOrg_$$_javassist_0.java)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
 at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
 at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
 at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
 at org.apache.jsp.jsp.frame.top_jsp._jspService(top_jsp.java:241)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at cn.edu.cuit.disasterSystem.web.filter.SessionInalidateFilter.doFilter(SessionInalidateFilter.java:54)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at cn.edu.cuit.disasterSystem.web.filter.SecurityValidateFilter.doFilter(SecurityValidateFilter.java:43)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:99)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
 at java.lang.Thread.run(Thread.java:619)



先说一下大体得情况...我现在做这个项目的实体关系比较多,所有不能使用lazy="false"...

而我也配置了..openSessionInViewFilter,为什么openSessionInViewFilter不好使了呢.....而且应该没得问题.....请高手指教,或者提供更好的方法..

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


    
<!-- spring support -->
    
<listener>
        
<listener-class>
            org.springframework.web.context.ContextLoaderListener
        
</listener-class>
    
</listener>
    
    
<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>
            classpath:applicationContext.xml,classpath:applicationContext
-*.xml
        
</param-value>
    
</context-param>

    
<!-- hibernate session support -->
    
<filter>
        
<filter-name>openSessionInViewFilter</filter-name>
        
<filter-class>
            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        
</filter-class>
    
</filter>
    
    
<filter-mapping>
        
<filter-name>openSessionInViewFilter</filter-name>
        
<url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener>


    


    <!-- struts2 support -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ActionContextCleanUp
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    

    <!-- DataSource -->
    <!-- 
        <resource-ref>
        <description>SQLServer2005 Datasource disasterSystem</description>
        <res-ref-name>jdbc/sqlserver</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        </resource-ref>
    -->


    
    <!-- welcome homepage -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>


    <!-- CharacterEncoding support -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    
    
    
    <!-- dwr support -->
    <servlet>
        <servlet-name>dwr</servlet-name>
        <servlet-class>
            org.directwebremoting.servlet.DwrServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dwr</servlet-name>
        <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>
    


    <!-- 系统权限认证过滤器,如果不进行权限认证可以将isValidate设置为false -->
    <filter>
        <filter-name>SecurityValidateFilter</filter-name>
        <filter-class>cn.edu.cuit.disasterSystem.web.filter.SecurityValidateFilter</filter-class>
        <init-param>
            <param-name>isValidate</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SecurityValidateFilter</filter-name>
        <url-pattern>/jsp/*</url-pattern>
    </filter-mapping>
    
    
    <!-- Session过期处理过滤器,如果不进行处理可以将isValidate设置为false -->
    <filter>
        <filter-name>SessionInalidateFilter</filter-name>
        <filter-class>cn.edu.cuit.disasterSystem.web.filter.SessionInalidateFilter</filter-class>
        <init-param>
            <param-name>isValidate</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>inalidateTime</param-name>
            <param-value>30000</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SessionInalidateFilter</filter-name>
        <url-pattern>/jsp/*</url-pattern>
    </filter-mapping>


    <!-- build validate code,现已改成jsp实现 -->
    <servlet>
        <servlet-name>ValidateCodeServlet</servlet-name>
        <servlet-class>
            cn.edu.cuit.disasterSystem.web.servlet.ValidateCodeServlet
        </servlet-class>
        <init-param>
            <param-name>width</param-name>
            <param-value>70</param-value>
        </init-param>
        <init-param>
            <param-name>height</param-name>
            <param-value>19</param-value>
        </init-param>
        <init-param>
            <param-name>codeCount</param-name>
            <param-value>4</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>ValidateCodeServlet</servlet-name>
        <url-pattern>/validateCodeServlet</url-pattern>
    </servlet-mapping>

    <!-- 统一配置404错误,500错误的异常处理页面 -->
    <error-page>
        <error-code>404</error-code>
        <location>/404.jsp</location>
    </error-page>

    <error-page>
        <error-code>500</error-code>
        <location>/500.jsp</location>
    </error-page>
</web-app>




总结:日,浪费我一天时间,原来出现两个错误,改了这一个,忘改另一个,结果弄了一天,,晕晕晕,终于解决问题了,在这总结一下:
    出现第一个错误:Spring配置的声明式事务,到Service完成以后就强制提交事务,关闭Session了。。所以报Lazy错误
   第二是因为:web.xml里面配置顺序出错,也就是OpenSessionInViewFilter没起到作用。。
  

下面是web.xml配置顺序,

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>



    
<!-- 指定Spring配置文件 -->
    
<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>
            classpath:applicationContext.xml,classpath:applicationContext-*.xml
        
</param-value>
    
</context-param>
    
<!-- 对Spring容器进行实例化 -->
    
<listener>
        
<listener-class>
            org.springframework.web.context.ContextLoaderListener
        
</listener-class>
    
</listener>
    
<listener>
        
<listener-class>
            org.springframework.web.context.request.RequestContextListener
        
</listener-class>
    
</listener>

    
<!-- struts2一定要在OpenSessionInViewFilter前面初始化 -->
    
<filter>
        
<filter-name>struts-cleanup</filter-name>
        
<filter-class>
            org.apache.struts2.dispatcher.ActionContextCleanUp
        
</filter-class>
    
</filter>
    
<filter-mapping>
        
<filter-name>struts-cleanup</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>
    
<filter>
        
<filter-name>struts2</filter-name>
        
<filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        
</filter-class>
    
</filter>
    
<filter-mapping>
        
<filter-name>struts2</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>

    
<!-- OpenSessionInViewFilter一定要在struts2后面初始化才行 -->
    
<filter>
        
<filter-name>OpenSessionInViewFilter</filter-name>
        
<filter-class>
            org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
        
</filter-class>
    
</filter>
    
<filter-mapping>
        
<filter-name>OpenSessionInViewFilter</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>



    
<welcome-file-list>
        
<welcome-file>index.jsp</welcome-file>
    
</welcome-file-list>



    
<!-- dwr support -->
    
<servlet>
        
<servlet-name>dwr</servlet-name>
        
<servlet-class>
            org.directwebremoting.servlet.DwrServlet
        
</servlet-class>
        
<init-param>
            
<param-name>debug</param-name>
            
<param-value>true</param-value>
        
</init-param>
        
<load-on-startup>1</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>dwr</servlet-name>
        
<url-pattern>/dwr/*</url-pattern>
    
</servlet-mapping>



    
<!-- 系统权限认证过滤器,如果不进行权限认证可以将isValidate设置为false -->
    
<filter>
        
<filter-name>SecurityValidateFilter</filter-name>
        
<filter-class>
            cn.edu.cuit.disasterSystem.web.filter.SecurityValidateFilter
        
</filter-class>
        
<init-param>
            
<param-name>isValidate</param-name>
            
<param-value>true</param-value>
        
</init-param>
    
</filter>
    
<filter-mapping>
        
<filter-name>SecurityValidateFilter</filter-name>
        
<url-pattern>/jsp/*</url-pattern>
    
</filter-mapping>


    
<!-- Session过期处理过滤器,如果不进行处理可以将isValidate设置为false -->
    
<filter>
        
<filter-name>SessionInalidateFilter</filter-name>
        
<filter-class>
            cn.edu.cuit.disasterSystem.web.filter.SessionInalidateFilter
        
</filter-class>
        
<init-param>
            
<param-name>isValidate</param-name>
            
<param-value>true</param-value>
        
</init-param>
        
<init-param>
            
<param-name>inalidateTime</param-name>
            
<param-value>30000</param-value>
        
</init-param>
    
</filter>
    
<filter-mapping>
        
<filter-name>SessionInalidateFilter</filter-name>
        
<url-pattern>/jsp/*</url-pattern>
    
</filter-mapping>


    
<!-- build validate code,现已改成jsp实现 -->
    
<servlet>
        
<servlet-name>ValidateCodeServlet</servlet-name>
        
<servlet-class>
            cn.edu.cuit.disasterSystem.web.servlet.ValidateCodeServlet
        
</servlet-class>
        
<init-param>
            
<param-name>width</param-name>
            
<param-value>70</param-value>
        
</init-param>
        
<init-param>
            
<param-name>height</param-name>
            
<param-value>19</param-value>
        
</init-param>
        
<init-param>
            
<param-name>codeCount</param-name>
            
<param-value>4</param-value>
        
</init-param>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>ValidateCodeServlet</servlet-name>
        
<url-pattern>/validateCodeServlet</url-pattern>
    
</servlet-mapping>

    
<!-- 统一配置404错误,500错误的异常处理页面 -->
    
<error-page>
        
<error-code>404</error-code>
        
<location>/404.jsp</location>
    
</error-page>

    
<error-page>
        
<error-code>500</error-code>
        
<location>/500.jsp</location>
    
</error-page>

    
<!-- log4j配置 -->
    
<context-param>
        
<param-name>log4jConfigLocation</param-name>
        
<param-value>/WEB-INF/log4j.properties</param-value>
    
</context-param>
    
<context-param>
        
<param-name>log4jRefreshInterval</param-name>
        
<param-value>6000</param-value>
    
</context-param>
    
<listener>
        
<listener-class>
            org.springframework.web.util.Log4jConfigListener
        
</listener-class>
    
</listener>
</web-app>



 但是这样也出现在一个新的问题,就是spring 的声明式事务出错...  
 

  希望高手们能解决...


使用Spring AOP声明式异常,会使用OpenSessionInviewfilter无效 .. .



下面是我Spring声明式异常的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop
="http://www.springframework.org/schema/aop"
    xmlns:tx
="http://www.springframework.org/schema/tx"
    xsi:schemaLocation
="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
>
    
    
<!-- 
        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/sqlserver">
        </property>
        </bean>
    
-->

    
<bean id="sessionFactory"
        class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="configLocation"
            value
="classpath:hibernate.cfg.xml">
        
</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="del*" propagation="REQUIRED" />
            
<tx:method name="modify*" propagation="REQUIRED" />
            
<tx:method name="*" read-only="true" />
        
</tx:attributes>
    
</tx:advice>
     
    
<!-- 配置事务关联包 -->
    
<aop:config>
        
<aop:pointcut id="allServiceMethod"
            expression
="execution(* cn.edu.cuit.disasterSystem.business.service..*.*(..))" />
        
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
    
</aop:config>
</beans>








名称: ♪4C.ESL | .↗Evon
口号: 遇到新问题♪先要寻找一个方案乄而不是创造一个方案こ
mail: 联系我


Feedback

# re: 高手们...救救我吧...org.hibernate.LazyInitializationException: could not initialize proxy - no Session  回复  更多评论   

2009-11-22 02:03 by xcp
自己顶起!!

# re: 高手们...救救我吧...org.hibernate.LazyInitializationException: could not initialize proxy - no Session  回复  更多评论   

2009-11-22 15:00 by 凡客衬衫
大风歌梵蒂冈

# re: 高手们...救救我吧...org.hibernate.LazyInitializationException: could not initialize proxy - no Session  回复  更多评论   

2009-11-22 18:06 by xcp
日..原来有两个错误 一个是我配置的声明式事务把Session关了..另一个是配置OpenSessionInViewFilter必须在struts2后面才行..


# re: 高手们...救救我吧...org.hibernate.LazyInitializationException: could not initialize proxy - no Session(已解决)  回复  更多评论   

2009-11-22 22:09 by bobby
在这里声明式事务不能用吗?

# re: org.hibernate.LazyInitializationException: could not initialize proxy - no Session  回复  更多评论   

2009-11-24 19:25 by xcp
@bobby
恩 .肯定有冲突..

不过.我们不对其它的查询设置事务就OK了..

例: 把这句话删了<tx:method name="*" read-only="true" />

# re: org.hibernate.LazyInitializationException: could not initialize proxy - no Session  回复  更多评论   

2009-11-26 13:17 by bobby
这个其实与事务没有关系,你试试把OpensessionInViewFilter过滤器放在Struts2之前过滤就可以了,试一下,我的就是这样解决的!

只有注册用户登录后才能发表评论。


网站导航: