title: JCR Re-opening Connections
body: <p>I am using JCR 1.0 and I am having problems re-opening JCR connections after I close them.</p>
  
  <p>Here are my two helper methods:</p>
  
  <pre><code>private void openConnection() throws Exception {
      loadDbProperties();
  
      repository = new TransientRepository(repositoryConfig,repositoryHome);
      session = repository.login(new SimpleCredentials("testUserName","testPassword".toCharArray()));
  
      ws = session.getWorkspace();
  
      rootNode = session.getRootNode();
  }
  
  private void closeConnection() throws Exception {
      session.save();
      session.logout();
      session = null;
      repository = null;
  }
  </code></pre>
  
  <p>I have two methods called, addProperty() and getProperty(), both need a connection to the JCR repository.  I placed the openConnection() and closeConnection() methods at the beginning of both add and get methods but it seems that whichever method runs second is not able to re-open an already closed connection.</p>
  
  <p>This is the exception I get:</p>
  
  <pre><code>javax.faces.el.EvaluationException: javax.jcr.RepositoryException: this session has been closed
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:550)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:619)
  Caused by: javax.jcr.RepositoryException: this session has been closed
      at org.apache.jackrabbit.core.SessionImpl.sanityCheck(SessionImpl.java:340)
      at org.apache.jackrabbit.core.ItemImpl.sanityCheck(ItemImpl.java:154)
      at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1751)
      at pgts.trueMiner.core.dao.TenureDAOImpl.addTenure(TenureDAOImpl.java:63)
      at pgts.trueMiner.core.biz.TenureServiceImpl.addTenure(TenureServiceImpl.java:63)
      at pgts.trueMiner.core.ui.TenureForm.addTenure(TenureForm.java:50)
      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 com.sun.el.parser.AstValue.invoke(AstValue.java:234)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:98)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
      ... 23 more
  </code></pre>
  
  <p>How do you re-open the same connection?  I don't want to always keep the connection open because a lock will prevent other applications from using the repository.</p>