У меня есть сущность, сопоставленная с Spring Data Rest, и проверенная перед сохранением с использованием этой конфигурации:
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
validatingListener.addValidator("beforeCreate", this.validator);
validatingListener.addValidator("beforeSave", this.validator);
}
У сущности есть несколько коллекций LAZY, и, к сожалению, когда она проверяется hibernate через Bean Validation, она выдает исключение:
"не удалось лениво инициализировать коллекцию ролей:"
Есть способ сообщить Spring, чтобы разрешить открытие транзакции, чтобы можно было загружать отложенные коллекции?
Спасибо
Ниже трассировки стека
org.hibernate.LazyInitializationException: не удалось лениво инициализировать коллекцию ролей: com.myFleetSolutions.myFleet.fleet.domain.entity.car.Car.traceRequests, не удалось инициализировать прокси - нет сеанса
в org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException (AbstractPersistentCollection.java:582) ~ [hibernate-core-5.2.17.Final.jar: 5.2.17.Final]
at org.hibernate.collection.internal.AbstractPersistentCollection.withTeorarySessionIfNeeded (AbstractPersistentCollection.java:201) ~ [hibernate-core-5.2.17.Final.jar: 5.2.17.Final]
в org.hibernate.collection.internal.AbstractPersistentCollection.readSize (AbstractPersistentCollection.java:145) ~ [hibernate-core-5.2.17.Final.jar: 5.2.17.Final]
в org.hibernate.collection.internal.PersistentBag.size (PersistentBag.java:261) ~ [hibernate-core-5.2.17.Final.jar: 5.2.17.Final]
в org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues (ListValueExtractor.java:25) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
в org.hibernate.validator.internal.engine.valueextraction.ListValueExtractor.extractValues (ListValueExtractor.java:16) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
at org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues (ValueExtractorHelper.java:42) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedContainerElementsForCurrentGroup (ValidatorImpl.java:627) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
в org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints (ValidatorImpl.java:576) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
в org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext (ValidatorImpl.java:389) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
в org.hibernate.validator.internal.engine.ValidatorImpl.validate (ValidatorImpl.java:169) ~ [hibernate-validator-6.0.9.Final.jar: 6.0.9.Final]
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate (SpringValidatorAdapter.java:104) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.validation.ValidationUtils.invokeValidator (ValidationUtils.java:88) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.validation.ValidationUtils.invokeValidator (ValidationUtils.java:56) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
at org.springframework.data.rest.core.event.ValidatingRepositoryEventListener.validate (ValidatingRepositoryEventListener.java:174) ~ [spring-data-rest-core-3.0.7.RELEASE.jar: 3.0.7.RELEASE]
at org.springframework.data.rest.core.event.ValidatingRepositoryEventListener.onBeforeSave (ValidatingRepositoryEventListener.java:114) ~ [spring-data-rest-core-3.0.7.RELEASE.jar: 3.0.7.RELEASE]
at org.springframework.data.rest.core.event.AbstractRepositoryEventListener.onApplicationEvent (AbstractRepositoryEventListener.java:48) ~ [spring-data-rest-core-3.0.7.RELEASE.jar: 3.0.7.RELEASE]
at org.springframework.data.rest.core.event.AbstractRepositoryEventListener.onApplicationEvent (AbstractRepositoryEventListener.java:29) ~ [spring-data-rest-core-3.0.7.RELEASE.jar: 3.0.7.RELEASE]в org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener (SimpleApplicationEventMulticaster.java:172) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener (SimpleApplicationEventMulticaster.java:165) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent (SimpleApplicationEventMulticaster.java:139) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.context.support.AbstractApplicationContext.publishEvent (AbstractApplicationContext.java:400) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent (AbstractApplicationContext.java:354) ~ [spring-context-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
at org.springframework.data.rest.webmvc.RepositoryEntityController.saveAndReturn (RepositoryEntityController.java:447) ~ [spring-data-rest-webmvc-3.0.7.RELEASE.jar: 3.0.7.RELEASE]
at org.springframework.data.rest.webmvc.RepositoryEntityController.patchItemResource (RepositoryEntityController.java:397) ~ [spring-data-rest-webmvc-3.0.7.RELEASE.jar: 3.0.7.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод) ~ [na: 1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke (неизвестный источник) ~ [na: 1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke (Неизвестный источник) ~ [na: 1.8.0_171]
at java.lang.reflect.Method.invoke (Неизвестный источник) ~ [na: 1.8.0_171]
в org.springframework.web.method.support.InvocableHandlerMethod.doInvoke (InvocableHandlerMethod.java:209) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (InvocableHandlerMethod.java:136) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle (ServletInvocableHandlerMethod.java:102) ~ [spring-webmvc-5.0.6.RELEASE.jELE: 5.0.6.Re.
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod (RequestMappingHandlerAdapter.java:877) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal (RequestMappingHandlerAdapter.java:783) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle (AbstractHandlerMethodAdapter.java:87) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.servlet.DispatcherServlet.doDispatch (DispatcherServlet.java:991) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.servlet.DispatcherServlet.doService (DispatcherServlet.java:925) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.servlet.FrameworkServlet.processRequest (FrameworkServlet.java:974) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.servlet.FrameworkServlet.service (FrameworkServlet.java:848) ~ [spring-webmvc-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в javax.servlet.http.HttpServlet.service (HttpServlet.java:742) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:231) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52) ~ [tomcat-embed-websocket-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
at org.springframework.web.filter.AbstractRequestLoggingFilter.doFilterInternal (AbstractRequestLoggingFilter.java:245) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
at org.springframework.web.filter.AbstractRequestLoggingFilter.doFilterInternal (AbstractRequestLoggingFilter.java:245) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.springframework.web.filter.CorsFilter.doFilterInternal (CorsFilter.java:96) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
at org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter.doFilter (OAuth2ClientContextFilter.java:60) ~ [spring-security-oauth2-2.3.3.RELEASE.jar: na]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics (WebMvcMetricsFilter.java:158) ~ [spring-boot-activator-2.0.2.RELEASE.jar: 2.0.2.RELEASE]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics (WebMvcMetricsFilter.java:126) ~ [spring-boot-activator-2.0.2.RELEASE.jar: 2.0.2.RELEASE]
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal (WebMvcMetricsFilter.java:111) ~ [spring-boot-activator-2.0.2.RELEASE.jar: 2.0.2.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal (HttpTraceFilter.java:84) ~ [spring-boot-actator-2.0.2.RELEASE.jar: 2.0.2.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:320) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke (FilterSecurityInterceptor.java:127) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter (FilterSecurityInterceptor.java:91) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.access.ExceptionTranslationFilter.doFilter (ExceptionTranslationFilter.java:119) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.session.SessionManagementFilter.doFilter (SessionManagementFilter.java:137) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter (AnonymousAuthenticationFilter.java:111) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter (SecurityContextHolderAwareRequestFilter.java:170) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter (RequestCacheAwareFilter.java:63) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.doFilter (OAuth2AuthenticationProcessingFilter.java:176) ~ [spring-security-oauth2-2.3.3.RELEASE.jar: na]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.authentication.logout.LogoutFilter.doFilter (LogoutFilter.java:116) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal (HeaderWriterFilter.java:66) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter (SecurityContextPersistenceFilter.java:105) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal (WebAsyncManagerIntegrationFilter.java:56) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.web.filter.OncePerRequestFilter.doFilter (OncePerRequestFilter.java:107) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter (FilterChainProxy.java:334) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy.doFilterInternal (FilterChainProxy.java:215) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.security.web.FilterChainProxy.doFilter (FilterChainProxy.java:178) ~ [spring-security-web-5.0.5.RELEASE.jar: 5.0.5.RELEASE]
в org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate (DelegatingFilterProxy.java:357) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.springframework.web.filter.DelegatingFilterProxy.doFilter (DelegatingFilterProxy.java:270) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]
в org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:166) ~ [tomcat-embed-core-8.5.31.jar: 8.5.31]
в org.springframework.web.filter.RequestContextFilter.doFilterInternal (RequestContextFilter.java:99) ~ [spring-web-5.0.6.RELEASE.jar: 5.0.6.RELEASE]