我正在尝试使用 JPA、Google Cloud SQL 和本地 MySQL 数据库开发 Google App Engine 应用程序。我正在使用 GAE eclipse 插件。我已经注册了一个谷歌云 SQL 实例。将项目的应用引擎设置配置为使用 Google Cloud SQL,并为本地 MySQL 数据库和云 SQL 实例输入连接信息。
数据核增强器提取了我的 57 个类,我看到日志中的类已成功优化。我在 Eclipse 中运行我的应用程序,开发环境成功启动,我可以通过浏览器访问我的应用程序。
问题是无法通过 JPA 调用检索数据库中的数据。我在应用程序输出中看不到任何错误。我通过调试器运行,JPA 调用成功运行,没有在我的应用程序源代码中引发异常。我从检索中得到一个空列表。
我不确定在这里做什么。我已经在网上研究了很长时间,但我无法弄清楚我做错了什么。当我没有异常或要使用的东西时,很难追踪到一些东西。
我的猜测是有些事情失败了,但错误可能会被吞下,或者可能是一个限制。我还尝试通过使用标准生成器然后直接使用 JPQL 来更改 JPA 调用。仍然得到相同的结果。
检查了开发服务器的参数,我看到了从我为本地 mysql 服务器输入的配置中使用的参数。是否有可能以某种方式忽略这些论点?
任何帮助,将不胜感激。
Persistence.xml -(只有 2 个用于测试的类)
<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 调用:
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;
}
控制台输出:
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 SelectChannelConnector@127.0.0.1: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