java - Use Google Data Store and Google App Engine in same application -


i have application storing data in google cloud sql . think tables can moved google datastore . question how can use both data store , cloud sql using same application . tried checking both option datastore , cloud sql persisting in cloud sql .

this persistence.xml file .

<?xml version="1.0" encoding="utf-8" ?> <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">      <persistence-unit name="transactions-optional1">         <provider>org.datanucleus.api.jpa.persistenceproviderimpl</provider>         <class>com.sample.poc.component</class>         <properties>             <property name="datanucleus.nontransactionalread" value="true"/>             <property name="datanucleus.nontransactionalwrite" value="true"/>             <property name="datanucleus.connectionurl" value="appengine"/>             <property name="datanucleus.singletonemfforname" value="true"/>         </properties>      </persistence-unit>       <persistence-unit name="transactions-optional2"         transaction-type="resource_local">         <provider> org.datanucleus.jpa.persistenceproviderimpl</provider>         <class>com.sample.poc.user</class>         <class>com.sample.poc.role</class>          <properties>           <property name="javax.persistence.jdbc.driver"                 value="com.google.appengine.api.rdbms.appenginedriver" />             <property name="javax.persistence.jdbc.url"                 value="jdbc:google:rdbms://span-test-app:testinstance/pocdb" />             <property name="javax.persistence.jdbc.user" value="" />             <property name="javax.persistence.jdbc.password" value="" />         </properties>      </persistence-unit>  </persistence> 

here 2 emf beans:

for datastore:

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;     } } 

here emf bean cloud sql:

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;     } } 

here's servlet inserting component in datastore:

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();     } }  } 

i want user,role bean persisted in cloud sql , component in datastore.

when try insert component in datastore throws exception:

caused by: javax.persistence.persistenceexception: no persistence providers available "transactions-optional1" after trying following discovered implementations: org.datanucleus.api.jpa.persistenceproviderimpl     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:180)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:70)     @ com.sample.poc.emfds.<clinit>(emfds.java:9)     ... 40 more 12 aug, 2013 9:48:24 com.google.apphosting.utils.jetty.jettylogger warn warning: nested in java.lang.exceptionininitializererror: javax.persistence.persistenceexception: no persistence providers available "transactions-optional1" after trying following discovered implementations: org.datanucleus.api.jpa.persistenceproviderimpl     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:180)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:70) 

am missing thing . please suggest .

you have no "provider" specified 1 persistence-unit - jpa provider going use cloud-sql? specify it.

you have invalid "provider" other persistence-unit. gae jpa v2 "org.datanucleus.api.jpa.persistenceproviderimpl" message says, yet seem want use (very old, unsupported) gae jpa 1 variant. make sure have right 1 in classpath (and not other one)

which "jpa api" jar in classpath? (this not jpa implementation). if using gae jpa v2 need jpa api v2 (geronimo-jpa_2.0_spec) , not jpa api v1 (geronimo-jpa_3.0_spec). if 1 of jpa providers being used jpa2 other has too.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -