James May
James May

Reputation: 1

GAE google cloud sql JPA local mysql with empty results

I am trying to get a Development Google App Engine app working with JPA, Google Cloud SQL, and a local MySQL database. I am using the GAE eclipse plugin. I have signed up for a Google cloud SQL instance. Configured the app engine settings on the project to use Google Cloud SQL and put in the connectivity info for the local MySQL database and for the cloud SQL instance.

The data nucleus enhancers picks up my 57 classes and I see the log with the classes successfully optimized. I run my application within Eclipse and the dev environment fires up successfully and I can get to my app through the browser.

The issue is that the data in the database cannot be retrieved through from the JPA calls. I don't see any errors in the application output. I run through the debugger and the JPA calls run successfully without throwing an exception in my app source code. I get an empty list from retrieval.

I am not sure what to do here. I have researched online for quite some time and I can't figure out what I am doing wrong. It is hard to track something down when I don't have an exception or something to use.

My guess is that there is something failing but the error could be swallowed or maybe a restriction. I also tried changing the JPA calls by using criteria builder and then using straight up JPQL. Still get the same results.

Checked the arguments to the dev server and I see the arguments that are being used from the configuration that I typed in for the local mysql server. Is it possible that the arguments are being ignored somehow?

Any help would be appreciated.

Persistence.xml - (with only 2 classes for testing)

<persistence-unit name="iberis-jpa">
    <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
    <class>com.bizznetworxonline.iberis.core.SystemArea</class>
    <class>com.bizznetworxonline.iberis.core.SystemUnit</class>

    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="datanucleus.NontransactionalRead" value="true"/>
        <property name="datanucleus.NontransactionalWrite" value="true"/>
        <property name="datanucleus.ConnectionURL" value="appengine"/>
    </properties>
</persistence-unit>

JPQL call:

public List<?> findAll(Class<?> entityClass) 
{

    EntityManager em = JPA_EMF.get().createEntityManager();

    javax.persistence.Query q = em.createQuery("SELECT o FROM " + entityClass.getSimpleName() + " o",entityClass);

    List<?> results = q.getResultList();

    return results;
}

Output from console:

Mar 30, 2013 9:49:06 PM com.google.apphosting.utils.config.AppEngineWebXmlReader    readAppEngineWebXml

INFO: Successfully processed /home/user/Documents/eclipse-workspace/IberisAdmin/war/WEB-INF/appengine-web.xml

Mar 30, 2013 9:49:06 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml

INFO: Successfully processed /home/user/Documents/eclipse-workspace/IberisAdmin/war/WEB-INF/web.xml

Mar 30, 2013 9:49:06 PM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties

INFO: Overwriting system property key 'java.util.logging.config.file', value '/home/user/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/com.google.appengine.eclipse.sdkbundle_1.7.6/appengine-java-sdk-1.7.6/config/sdk/logging.properties' with value 'WEB-INF/logging.properties' from '/home/user/Documents/eclipse-workspace/IberisAdmin/war/WEB-INF/appengine-web.xml'

Mar 30, 2013 9:49:07 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger

Mar 30, 2013 9:49:07 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: jetty-6.1.x

Mar 30, 2013 9:49:10 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.1.12 ( 20120814-1522) for context ''

Mar 30, 2013 9:49:13 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.

Mar 30, 2013 9:49:21 PM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
INFO: Running on PrimeFaces 3.5

Mar 30, 2013 9:49:21 PM org.primefaces.extensions.application.PostConstructApplicationEventListener processEvent
INFO: Running on PrimeFaces Extensions 0.6.3

Mar 30, 2013 9:49:22 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Started [email protected]:8888

Mar 30, 2013 9:49:22 PM com.google.appengine.tools.development.AbstractServer startup
INFO: Server default is running at http://localhost:8888/

Mar 30, 2013 9:49:22 PM com.google.appengine.tools.development.AbstractServer startup
INFO: The admin console is running at http://localhost:8888/_ah/admin

Mar 30, 2013 9:49:22 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: Dev App Server is now running

Mar 30, 2013 9:49:35 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init
INFO: Local Datastore initialized: 
Type: High Replication
Storage: /home/user/Documents/eclipse-workspace/IberisAdmin/war/WEB-INF/appengine-generated/local_db.bin

Mar 30, 2013 9:49:35 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load
INFO: The backing store, /home/user/Documents/eclipse-workspace/IberisAdmin/war/WEB-   INF/appengine-generated/local_db.bin, does not exist. It will be created.

Mar 30, 2013 9:49:37 PM com.google.apphosting.utils.jetty.JettyLogger warn

Upvotes: 0

Views: 593

Answers (2)

Takashi Matsuo
Takashi Matsuo

Reputation: 3436

I think the following element:

<property name="datanucleus.ConnectionURL" value="appengine"/>

is the culprit. This is a setting to use App Engine datastore as the storage layer.

Can you try the following?

First, please edit your persistence.xml as follows:

<properties>
    <!-- Remove the above property and add the following two -->
    <property name="javax.persistence.jdbc.driver" value="com.google.appengine.api.rdbms.AppEngineDriver" />
    <property name="javax.persistence.jdbc.url" value="jdbc:google:rdbms://your-project:your-instance/database_name" />
</properties>

Put datanucleus-rdbms-x.y.z.jar to the war/WEB-INF/lib directory and put mysql-connector-java-x.y.z-bin.jar to the appengine-sdk/lib/impl directory if you haven't.

Upvotes: 1

Holla
Holla

Reputation: 152

The Problem is with the query i guess.

Try to change the query some thing Similar to examples shown in below link http://www.datanucleus.org/products/accessplatform_3_0/jpa/jpql.html

Criteria's are not supported as of my knowledge

If it did'nt work, Share your entityClass Controllers as well.

Upvotes: 0

Related Questions