我刚刚更新从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