java - 如何在 AppEngine 中使用 JPA 2 获取实体、在 GWT 中更新并保存?

标签 java google-app-engine gwt jpa datanucleus

在 GWT 中更新一些实体后,我想保存它们。但是,当我尝试保留它们时,当我查看 AppEngine 管理界面时,它不会保存。 boolean 值没有改变。

代码

    EntityManager em = EMF.get().createEntityManager();
    for (OnixUser s: admin) {
        log.info(s.email + ", " + s.isAdmin);
        em.merge(s);  
    }
    em.close();

更新交易

    EntityManager em = EMF.get().createEntityManager();
    em.getTransaction().begin();
    for (OnixUser s: admin) {
        log.info(s.email + ", " + s.isAdmin);
        OnixUser merged = em.merge(s);
        em.persist(merged);
//          em.persist(s);
    }
    em.getTransaction().commit();
    em.close();

还是没有保存。没有抛出异常。

日志

 Oct 16, 2013 3:19:10 PM com.example.sdm.server.SDMServiceImpl setAdmin
 INFO: chloe@example.com, true

OnixUser 实体的 App Engine 管理界面

Imgur

以最佳级别登录

FINE: Created ManagedConnection using DatastoreService = com.google.appengine.api.datastore.DatastoreServiceImpl@2fd9270d
Oct 16, 2013 4:03:14 PM org.datanucleus.store.connection.ConnectionManagerImpl allocateConnection
FINE: Connection added to the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@31c1f89d for key=org.datanucleus.ObjectManagerImpl@6977c57b in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@2b1f5f6b]
Oct 16, 2013 4:03:14 PM com.example.sdm.server.SDMServiceImpl setAdmin
INFO: chloe@example.com, true
Oct 16, 2013 4:03:14 PM org.datanucleus.state.LifeCycleState changeState
FINE: Object "com.example.sdm.shared.OnixUser@48ef6e99" (id="com.example.sdm.shared.OnixUser:6456332278300672") has a lifecycle change : "P_CLEAN"->"P_NONTRANS"
Oct 16, 2013 4:03:14 PM org.datanucleus.store.connection.ConnectionManagerImpl$1 managedConnectionPostClose
FINE: Connection removed from the pool : com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl$DatastoreManagedConnection@31c1f89d for key=org.datanucleus.ObjectManagerImpl@6977c57b in factory=ConnectionFactory:tx[com.google.appengine.datanucleus.DatastoreConnectionFactoryImpl@2b1f5f6b]
Oct 16, 2013 4:03:14 PM org.datanucleus.state.LifeCycleState changeState
FINE: Object "com.example.sdm.shared.OnixUser@48ef6e99" (id="com.example.sdm.shared.OnixUser:6456332278300672") has a lifecycle change : "P_NONTRANS"->"DETACHED_CLEAN"
Oct 16, 2013 4:03:14 PM com.google.apphosting.utils.jetty.AppEngineAuthentication$AppEngineUserRealm disassociate
FINE: Ignoring disassociate call for: chloe@example.com

最佳答案

如果尽管使用事务,您的数据并未持久保存,那么最好的方法是尝试记录日志以查看底层发生了什么。当您使用 DataNucleus 作为持久性提供程序时,您可以引用此 link配置 SQL 日志记录。与您相关的信息位于页面末尾附近。

关于java - 如何在 AppEngine 中使用 JPA 2 获取实体、在 GWT 中更新并保存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19411578/

相关文章:

java - 使用 JRebel 6.0.0 部署时,在 Spring 4.1.2 更新后找不到资源

python - 用Python NDB有效实现一对多关系

javascript - 使用GWT JSNI与js文件集成

java - 如何保护基于 XML 的数据源?

python - Google App Engine - 开发服务器上的代理/隧道权限被拒绝

java - 无法安装 GWT 开发人员插件

java - 在 Java EE 中重新运行失败的容器管理事务

java - 启动 100 个按钮的更有效方法

java - Android 如何从 Fragment 编辑操作栏菜单

python - 更新 Google NDB 实体上的多个字段