title: Use Google Data Store and Google App Engine in same application
body: <p>I have an application where i was storing all my data in Google Cloud SQL . But now i think that some the tables can be moved to Google datastore . So my question is how can use both Data Store and Cloud SQL using same application . I tried checking both the option for datastore and cloud SQL but its only persisting in Cloud SQL . </p>
  
  <p>This is my persistence.xml file . </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
      version="1.0"&gt;
  
      &lt;persistence-unit name="transactions-optional1"&gt;
          &lt;provider&gt;org.datanucleus.api.jpa.PersistenceProviderImpl&lt;/provider&gt;
          &lt;class&gt;com.sample.poc.Component&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="datanucleus.NontransactionalRead" value="true"/&gt;
              &lt;property name="datanucleus.NontransactionalWrite" value="true"/&gt;
              &lt;property name="datanucleus.ConnectionURL" value="appengine"/&gt;
              &lt;property name="datanucleus.singletonEMFForName" value="true"/&gt;
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  
  
      &lt;persistence-unit name="transactions-optional2"
          transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt; org.datanucleus.jpa.PersistenceProviderImpl&lt;/provider&gt;
          &lt;class&gt;com.sample.poc.User&lt;/class&gt;
          &lt;class&gt;com.sample.poc.Role&lt;/class&gt;
  
          &lt;properties&gt;
            &lt;property name="javax.persistence.jdbc.driver"
                  value="com.google.appengine.api.rdbms.AppEngineDriver" /&gt;
              &lt;property name="javax.persistence.jdbc.url"
                  value="jdbc:google:rdbms://span-test-app:testinstance/pocDB" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="" /&gt;
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Here is my two EMF beans:</p>
  
  <p>For Datastore:</p>
  
  <pre><code>package com.sample.poc;
  
  
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  public final class EMFDS {
      private static final EntityManagerFactory emfInstance = Persistence
              .createEntityManagerFactory("transactions-optional1");
  
      private EMFDS() {
      }
  
      public static EntityManagerFactory get() {
          return emfInstance;
      }
  }
  </code></pre>
  
  <p>Here is EMF bean for cloud sql:</p>
  
  <pre><code>package com.sample.poc;
  
  
  import javax.persistence.EntityManagerFactory;
  import javax.persistence.Persistence;
  
  public final class EMFRDBMS {
      private static final EntityManagerFactory emfInstance = Persistence
              .createEntityManagerFactory("transactions-optional");
  
      private EMFRDBMS() {
      }
  
      public static EntityManagerFactory get() {
          return emfInstance;
      }
  }
  </code></pre>
  
  <p>Here's the servlet for inserting component in datastore:</p>
  
  <pre><code>package com.sample.poc;
  
  import java.io.IOException;
  
  import javax.persistence.EntityManager;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class ComponentInsert extends HttpServlet {
  
      private static final long serialVersionUID = 1L;
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      String CompId = request.getParameter("CompId");  
      String CompName= request.getParameter("CompName");  
      response.setContentType("text/html");  
      EntityManager e = EMFDS.get().createEntityManager();
      try {
          e.getTransaction().begin();
          Component ob = new Component();
          ob.setCompId(Integer.parseInt(CompId));
          ob.setCompName(CompName);
          e.persist(ob);
          e.getTransaction().commit();
      } catch (Exception ex) {
          e.getTransaction().rollback();
          ex.printStackTrace();
      }
  }
  
  }
  </code></pre>
  
  <p>I just want user,role bean to be persisted in cloud sql and component in datastore.</p>
  
  <p>When i try to insert a component in datastore its throws this exception:</p>
  
  <pre><code>Caused by: javax.persistence.PersistenceException: No persistence providers available for "transactions-optional1" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:180)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
      at com.sample.poc.EMFDS.&lt;clinit&gt;(EMFDS.java:9)
      ... 40 more
  12 Aug, 2013 9:48:24 AM com.google.apphosting.utils.jetty.JettyLogger warn
  WARNING: Nested in java.lang.ExceptionInInitializerError:
  javax.persistence.PersistenceException: No persistence providers available for "transactions-optional1" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:180)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70)
  </code></pre>
  
  <p>Am I missing some thing . Please suggest .</p>