web-dev-qa-db-ja.com

Hibernateコレクションはどのセッションにも関連付けられていません

SOに関するこの問題に関していくつかの質問と回答を見つけましたが、それらはすべて、問題の1つの主な原因をカバーしているようです。しかし、私の場合、親オブジェクトとコレクションを取得するとき、同じトランザクション内で取得しています。

@Service
@Transactional
public class IntegrationServiceImpl implements IntegrationService {
@Override
    public Integration getIntegrationByIdFetchBackendParameters(Long integrationId) {
        Integration integration = integrationDao.get(integrationId);
        //not all integrations have to have backend.
        if (integration.getBackend() != null) {
            Hibernate.initialize(integration.getBackend().getBackendParameters());
        }
        return integration;
    }
...

しかし、Hibernate.initializeに関しては、org.hibernate.collection.internal.AbstractPersistentCollectionのこのブランチが実行されます

if ( session == null ) {
                throw new HibernateException( "collection is not associated with any session" );
            }

sessionnullである理由がわかりません。誰かがこれを説明して解決策を提案しますか?

編集1-完全なスタックトレース

org.hibernate.HibernateException: collection is not associated with any session
        at org.hibernate.collection.internal.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.Java:676)
        at org.hibernate.Hibernate.initialize(Hibernate.Java:77)
        at com.dhl.finFw.service.IntegrationServiceImpl.getIntegrationByIdFetchBackendParameters(IntegrationServiceImpl.Java:169)
        at com.dhl.finFw.web.integration.IntegrationOverviewManagedBean.loadIntegration(IntegrationOverviewManagedBean.Java:59)
        at com.dhl.finFw.web.integration.AbstractIntegrationManagedBean.initCommonFields(AbstractIntegrationManagedBean.Java:69)
        at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
        at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
        at Java.lang.reflect.Method.invoke(Method.Java:606)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.Java:344)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.Java:295)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.Java:130)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.Java:399)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.Java:1481)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:524)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:461)
        at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.Java:333)
        at com.dhl.finFw.spring.scope.ViewScope.get(ViewScope.Java:30)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:329)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:194)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.Java:1117)
        at org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.Java:56)
        at com.Sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.Java:176)
        at com.Sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.Java:203)
        at org.Apache.el.parser.AstIdentifier.getValue(AstIdentifier.Java:72)
        at org.Apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.Java:185)
        at com.Sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.Java:109)
        at org.Apache.el.parser.AstIdentifier.getValue(AstIdentifier.Java:68)
        at org.Apache.el.parser.AstValue.getValue(AstValue.Java:161)
        at org.Apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.Java:185)
        at com.Sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.Java:109)
        at com.Sun.faces.facelets.tag.jstl.core.ForEachHandler.apply(ForEachHandler.Java:161)
        at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.Java:95)
        at com.Sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.Java:166)
        at com.Sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.Java:93)
        at com.Sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.Java:87)
        at com.Sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.Java:320)
        at com.Sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.Java:379)
        at com.Sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.Java:358)
        at com.Sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.Java:199)
        at com.Sun.faces.facelets.tag.ui.IncludeHandler.apply(IncludeHandler.Java:120)
        at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.Java:95)
        at com.Sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.Java:106)
        at com.Sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.Java:178)
        at com.Sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.Java:395)
        at com.Sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.Java:366)
        at com.Sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.Java:111)
        at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.Java:95)
        at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.Java:137)
        at com.Sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.Java:187)
        at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.Java:120)
        at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.Java:95)
        at com.Sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.Java:179)
        at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.Java:95)
        at com.Sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.Java:93)
        at com.Sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.Java:87)
        at com.Sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.Java:320)
        at com.Sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.Java:379)
        at com.Sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.Java:358)
        at com.Sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.Java:199)
        at com.Sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.Java:155)
        at com.Sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.Java:93)
        at com.Sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.Java:87)
        at com.Sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.Java:164)
        at com.Sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.Java:870)
        at com.Sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.Java:99)
        at com.Sun.faces.lifecycle.Phase.doPhase(Phase.Java:101)
        at com.Sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.Java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.Java:594)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:305)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
        at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.Java:79)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
        at com.dhl.finFw.web.filter.FileNotFoundFilter.doFilter(FileNotFoundFilter.Java:40)
        at com.dhl.finFw.web.filter.FileNotFoundFilter.doFilter(FileNotFoundFilter.Java:35)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.Java:88)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.Java:107)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:330)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.Java:118)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.Java:84)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.Java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.Java:64)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.Java:103)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.Java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.Java:54)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.Java:45)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.Java:183)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.Java:105)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.Java:125)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.Java:87)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.Java:342)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.Java:192)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.Java:160)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.Java:346)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.Java:259)
        at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:243)
        at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
        at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:222)
        at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:123)
        at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:502)
        at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:171)
        at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:99)
        at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:953)
        at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118)
        at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:408)
        at org.Apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.Java:1023)
        at org.Apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.Java:589)
        at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:312)
        at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
        at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
        at Java.lang.Thread.run(Thread.Java:724)

編集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"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <bean id="environmentVariablesConfiguration"
          class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
        <property name="algorithm" value="PBEWithMD5AndDES" />
        <property name="passwordSysPropertyName" value="APP_ENCRYPTION" />
    </bean>

    <bean id="configurationEncryptor"
          class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
        <property name="config" ref="environmentVariablesConfiguration" />
    </bean>


    <bean id="propertyConfigurer"
          class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
        <constructor-arg ref="configurationEncryptor" />
        <property name="locations">
            <list>
                <value>${finFw.config.location}finFwUI.properties</value>
                <value>classpath:application.properties</value>
                <value>classpath:dateTime.properties</value>
            </list>
        </property>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
    </bean>

    <context:component-scan base-package="com.dhl.finFw"/>

    <context:annotation-config/>

    <tx:annotation-driven/>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="FINFW"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="${finFwUI.orm.generateDdl:false}"/>
                <property name="showSql" value="${finFwUI.orm.showSql:false}"/>
                <property name="databasePlatform" value="${finFwUI.orm.dialect}"/>
            </bean>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

    <aop:aspectj-autoproxy/>

    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
                <entry key="view">
                    <bean class="com.dhl.finFw.spring.scope.ViewScope"/>
                </entry>
            </map>
        </property>
    </bean>

    <bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
        <property name="attributes">
            <map>
                <entry key="finFwUIEnvironment" value="${finFwUI.environment}" />
            </map>
        </property>
    </bean>

    <bean id="eventListenerBean" class="com.dhl.finFw.spring.FinFwApplicationListener" />

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
    <display-name>FinFwUI</display-name>
    <description>Financial Framework Configuration</description>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>fileServlet</servlet-name>
        <servlet-class>com.dhl.finFw.web.FileServlet</servlet-class>
    </servlet>
    <!-- Location of the Log4J config file, for initialization and refresh checks.
        Applied by Log4jConfigListener. The variable is replaced with System property 
        at runtime. -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>${finFw.config.location}log4j-finFwUI.properties</param-value>
    </context-param>
    <!-- Application version. The variable is replaced during Maven build. -->
    <context-param>
        <param-name>applicationVersion</param-name>
        <param-value>${applicationVersion}</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>dhl</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
    </context-param>

    <!-- possible values: Development, Production, SystemTest, UnitTest The 
        variable is replaced during Maven build or set as System property during 
        development. -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>${finFwUI.jsf.stage}</param-value>
    </context-param>
    <!-- Spring application context config locations -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:com/dhl/finFw/finFwUI-core.xml
            classpath:com/dhl/finFw/finFwUI-dataSource.xml
            classpath:com/dhl/finFw/finFwUI-security.xml
            classpath:com/dhl/finFw/finFwUI-forms.xml
            classpath:com/dhl/finFw/finFwUI-audit.xml
        </param-value>
    </context-
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
    <!-- Configures Log4J for this web app. As this context specifies a context-param
        "log4jConfigLocation", its file path is used to load the Log4J configuration. -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- Starts Spring application context. The parent one. The web context 
        is started by Dispatcher servlet. -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>fileServlet</servlet-name>
        <url-pattern>/file/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/pages/protected/index.xhtml</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>encoding-filter</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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter>
        <filter-name>fileNotFoundFilter</filter-name>
        <filter-class>com.dhl.finFw.web.filter.FileNotFoundFilter</filter-class>
    </filter>

    <filter>
        <filter-name>browserCacheControlFilter</filter-name>
        <filter-class>com.dhl.finFw.web.filter.BrowserCacheControlFilter</filter-class>
    </filter>
    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>fileNotFoundFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>browserCacheControlFilter</filter-name>
        <url-pattern>/pages/protected/integration/subscriptionScheduler.xhtml</url-pattern>
    </filter-mapping>

    <error-page>
        <exception-type>org.springframework.security.access.AccessDeniedException</exception-type>
        <location>/pages/public/error/accessDenied.xhtml</location>
    </error-page>
    <error-page>
        <exception-type>Java.lang.Throwable</exception-type>
        <location>/pages/public/error/internal.xhtml</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/pages/public/error/internal.xhtml</location>
    </error-page>
    <error-page>
        <error-code>404</error-code>
        <location>/pages/public/error/notFound.xhtml</location>
    </error-page>
    <error-page>
        <error-code>403</error-code>
        <location>/pages/public/error/accessDenied.xhtml</location>
    </error-page>
</web-app>

ViewScope.Java

public class ViewScope implements Scope {

    private Logger logger = LoggerFactory.getLogger(getClass());

    public static final String VIEW_SCOPE_CALLBACKS = "viewScope.callbacks";

    @Override
    public Object get(String name, ObjectFactory<?> objectFactory) {
        Map<String, Object> viewMap = getViewMap();
        Object instance = viewMap.get(name);
        if (instance == null) {
            instance = objectFactory.getObject();
            synchronized (viewMap) {
                viewMap.put(name, instance);
                logger.debug("Bean '{}' has been put to ViewScope.", instance);
            }
        } else {
            logger.debug("Going to return an existing bean '{}'", instance);
        }
        return instance;
    }


    @Override
    public Object remove(String name) {
        Object instance = getViewMap().remove(name);
        if (instance != null) {
            Map<String, Runnable> callbacks = (Map<String, Runnable>) getViewMap().get(VIEW_SCOPE_CALLBACKS);
            if (callbacks != null) {
                callbacks.remove(name);
                logger.debug("Bean '{}' has been removed.", instance);
            }
        }
        return instance;
    }

    @Override
    public void registerDestructionCallback(String name, Runnable runnable) {
        Map<String, Runnable> callbacks = (Map<String, Runnable>) getViewMap().get(VIEW_SCOPE_CALLBACKS);
        if (callbacks != null) {
            callbacks.put(name, runnable);
            logger.debug("Registered callback for '{}'", name);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object resolveContextualObject(String name) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        FacesRequestAttributes facesRequestAttributes = new FacesRequestAttributes(facesContext);
        return facesRequestAttributes.resolveReference(name);
    }

    @Override
    public String getConversationId() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        FacesRequestAttributes facesRequestAttributes = new FacesRequestAttributes(facesContext);
        return facesRequestAttributes.getSessionId() + "-" + facesContext.getViewRoot().getViewId();
    }

    private Map<String, Object> getViewMap() {
        return FacesContext.getCurrentInstance().getViewRoot().getViewMap();
    }

}
18
DominikM

@Transactionalメソッドの上部。

10

アプリケーションでLazyLoadingExceptionを防ぐには、最初にエンティティをセッションにマージしてから要求されたコレクションを初期化するヘルパーメソッドを使用します。最近、セッションが開いているように見え、全体的に問題がないように見えるにもかかわらず、「コレクションがセッションに関連付けられていない」という問題が依然として発生することがあることが判明しました。そのような行動の原因は何かを言うのは難しいですが、それでも私はそれに対する治療法を見つけました。 session.refresh(entity)を使用して遅延コレクションを取得する前に、エンティティの状態を更新してください。これにより、HibernateがDBからエンティティをリロードします。これを実行した後、現在のセッションでは、Hibernate.initialize()を使用してコレクションをスムーズにロードできます。

@Zmicier Zaleznicenkaが指摘したように、この例外メッセージはセッションとは無関係かもしれません。この問題も発生しましたが、根本的な原因は、マッピングファイルで定義されたエンティティのプライマリキー設定が正しくなかったことです。たとえば、次のコードでは、データベース列「Foo_SK」はテーブルの一意の識別子ではありません。

Id(x => x.Id, "Foo_SK").GeneratedBy.Assigned();

この場合、データベーススキーマを制御することはできません。したがって、複合キーマッピングを使用して問題を修正しました。

同じ問題については他の投稿を確認してください。

2
Haohao Lin

@Transactionalメソッドの上部。また、次のようなIDでクラスを取得します。

Test s=get(test.getId())
1

私もこの問題を抱えていましたが、私にとっての問題は、構成ファイルでトランザクション管理を構成しなかったということでした:

追加 @EnableTransactionManagement to Java Configファイルまたは追加<tx:annotation-driven/> to xml config file

1
Pishtewan Agha

initAbstractIntegrationManagedBeanメソッドでこれを呼び出すようです。

その時点の前に休止状態が適切に設定されることを確認する必要があります。

ほとんどの場合、構成はそれを反映しておらず、休止状態が既に存在すると想定していますが、それを保証するものではありません。

詳細については、この質問を参照してください。 SpringでBean init-method呼び出しの順序を制御する方法?

0
Angelo Fuchs