title: Where to declare JDO Singleton PersistenceManagerFactory with multiple services
body: <p>I am working with GWT and have 4 Service Implementations that need a PersistenceManagerFactory.  I followed Google's advice on creating a singleton class, however I am unsure of where this class should be instantiated and referenced from in the server-side code.</p>
  
  <p>The class looks like this</p>
  
  <pre><code>import javax.jdo.JDOHelper;
  import javax.jdo.PersistenceManagerFactory;
  
  public final class PMF {
      private static final PersistenceManagerFactory pmfInstance =
          JDOHelper.getPersistenceManagerFactory("transactions-optional");
  
      private PMF() {}
  
      public static PersistenceManagerFactory get() {
          return pmfInstance;
      }
  }
  </code></pre>
  
  <p>But doing something like this in each Service Implementation seems to end up creating a unique copy of the singleton based on the error message I get "Application code attempted to create a PersistenceManagerFactory named transactions-optional, but one with this name already exists!"</p>
  
  <pre><code>@Override
   public void addCategory(Category category) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
          pm.makePersistent(category);
    } finally {
         pm.close();
       }
   }
  </code></pre>
  
  <p>So basically the first ServiceImpl that calls addCategory is fine, all others fail with the error above.  I am missing something vital here, I thought the whole point of the singleton class is to create a static PersistenceManagerFactory.  Any insights into what I am missing are greatly appreciated.</p>