我剛剛更新從SND 2一個項目,SDN3在Spring環境,並通過類似迫使傳統的簡單索引和索引TypeRepresentationStrategy必要的修改去訪問春數據Neo4j的trows NotInTransactionException。對已經獲取的對象
語境開機就好了,但考慮到下面的代碼...
@RequestMapping({"/customer/browse"})
public String customerBrowse(final ModelMap model) {
populateBaseModel(model);
Result<Customer> result = this.customerService.findAll();
for(Customer c : result) {
LOG.info("Customer: {}", c.getName());
}
model.addAttribute("allCustomer", result);
return "pages/browse";
}
...的的findAll()調用庫運行完美,同時檢索到的客戶僅僅訪問對象for(Customer c : result)
觸發NotInTransactionException(見下面)。 Customer類有幾個傳統索引註釋但沒有傳出引用。對我來說,不清楚爲什麼簡單訪問成功檢索的對象會遇到NotInTransactionException異常。我在簡單模式下運行SDN,並假定這個foreach正在分離的Customer對象上運行。異常之前
org.neo4j.graphdb.NotInTransactionException
at org.neo4j.index.impl.lucene.LuceneIndex.assertInTransaction(LuceneIndex.java:631)
at org.neo4j.index.impl.lucene.LuceneIndex.access$000(LuceneIndex.java:58)
at org.neo4j.index.impl.lucene.LuceneIndex$1.hasNext(LuceneIndex.java:359)
at org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)
at org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)
at com.myapp.controller.CustomerController.customerBrowse(CustomerController.java:56)
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.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1448)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:160)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
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: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:154)
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.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
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:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at com.github.dandelion.datatables.core.web.filter.DatatablesFilter.doFilter(DatatablesFilter.java:75)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at com.github.dandelion.core.web.DandelionFilter.doFilter(DandelionFilter.java:138)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:198)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:176)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.__doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:488)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:932)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:994)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:744)
跟蹤輸出:
| org.springframework.web.method.HandlerMethod | Invoking [CustomerController.customerBrowse] method with arguments [{}]
| o.s.d.r.c.s.TransactionalRepositoryProxyPostProcessor$CustomAnnotationTransactionAttributeSource | Adding transactional method 'findAll' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
| o.s.beans.factory.support.DefaultListableBeanFactory | Returning cached instance of singleton bean 'neo4jTransactionManager'
| o.springframework.transaction.jta.JtaTransactionManager | Creating new transaction with name [org.springframework.data.neo4j.repository.NodeGraphRepositoryImpl.findAll]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
| o.s.t.support.TransactionSynchronizationManager | Initializing transaction synchronization
| o.s.transaction.interceptor.TransactionInterceptor | Getting transaction for [org.springframework.data.neo4j.repository.NodeGraphRepositoryImpl.findAll]
| o.s.transaction.interceptor.TransactionInterceptor | Completing transaction for [org.springframework.data.neo4j.repository.NodeGraphRepositoryImpl.findAll]
| o.springframework.transaction.jta.JtaTransactionManager | Triggering beforeCommit synchronization
| o.springframework.transaction.jta.JtaTransactionManager | Triggering beforeCompletion synchronization
| o.springframework.transaction.jta.JtaTransactionManager | Initiating transaction commit
| o.springframework.transaction.jta.JtaTransactionManager | Triggering afterCommit synchronization
| o.springframework.transaction.jta.JtaTransactionManager | Triggering afterCompletion synchronization
| o.s.t.support.TransactionSynchronizationManager | Clearing transaction synchronization
本次交易範圍由下面的服務層處理:
@Service
@Transactional
public class CustomerService implements AssetService, ApplicationContextAware {
@Autowired
private CustomerRepository customerRepository;
...
public Result<Customer> findAll() {
return this.customerRepository.findAll();
}
...
}
的SDN關於自動交易手動會談照顧一些其方法。正如從日誌中看來的,這對findAll()調用很好,但是這仍然對檢索對象訪問失敗的原因保持開放。
真的很感激,如果任何人都可以點我排除故障朝着正確的方向。
我沒有給你答案,但這篇文章可能是相關閱讀。這是一個奇怪的問題;之前出現了類似的情況,而且沒有確定的解決方案。訣竅是找到一個可以真正重複的案例,我認爲。 https://groups.google.com/d/topic/neo4j/w1L_21z0z04/discussion – FrobberOfBits 2014-12-03 18:37:20
好像你不能工作了SDN的非事務性範圍提供結果或迭代器。如果我讓查詢返回集合/列表等,那麼事情在非事務範圍內工作。也許我錯過了這個文檔。 然而,這使得默認的findAll()無用的,如果你只是想通過自己的結果到視圖模板層(因爲這是出於交易範圍是肯定的)。您需要始終確保您只使用SDN結果類型直到服務層... – theeagermichael 2014-12-03 23:55:13
聲明:不知道詳細級別的SDN。 Neo4j 1.9 - > 2.x的其中一項變化是需要強制讀取事務。不是100%確定'findAll'在底層做了什麼,但我認爲迭代讀取了一些東西,因此需要一個你的控制器似乎沒有的事務上下文。 豈不是有意義的迭代重構爲返回一個列表''事務服務的方法? –
2014-12-04 16:13:56