【问题标题】:JDO and Cloud SQL update objects with makePersistentAllJDO 和 Cloud SQL 使用 makePersistentAll 更新对象
【发布时间】:2014-02-01 08:32:43
【问题描述】:

我正在使用带有 JDO 的谷歌云 SQL。当我尝试使用 JDO PersistenceManager 使用新密钥存储新对象时,它工作正常,但是当我尝试更新已插入数据库中的实体时出现错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '503062001-43661003' for key 'PRIMARY'

密钥确实是重复的,但我想更新那个对象。

是否可以使用 PersistentManager.makePersistentAll() 方法或以其他方式避免手动编写 UPDATE 查询?

更多详情: 我试图坚持的对象是这样定义的:

PersistenceCapable(table = "xxx")
public class XXX {

   @PrimaryKey
   @Index(name = "xxx_id")
   private Long userId;

   @PrimaryKey
   @Index(name = "xxx_idx")
   @Column(length = 128)
   private String otherId;
   ...
}

【问题讨论】:

    标签: google-app-engine jdo datanucleus google-cloud-sql


    【解决方案1】:

    如果你想更新对象,那么你首先检索对象,然后更新它(在同一个 txn 中,或者分离它并在分离时更新它)。所有这些都将在 JDO 规范中进行描述

    例如https://db.apache.org/jdo/pm.html 并向下翻页到“更新对象”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-20
      • 1970-01-01
      • 2020-05-18
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多