0

我在 GWT 项目中使用 datanucleus 和 jdo。使用 makePersistent() 将元素添加到数据库后如何检索生成的主键

编辑 我们使用注解,这里是主键:

    @PrimaryKey
@Column(name = "id_bla", allowsNull = "false")
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY, extensions = { @Extension(vendorName = "datanucleus", key = "strategy-when-notnull", value = "false") })
private Long idBla;

我不是做映射的人,我还没有得到所有这些。

4

1 回答 1

0

对象的键应在持久化时自动设置:

MyObject obj = new MyObject();
Long id = obj.getId();  // WRONG! Will still be null.
pm.makePersistent(obj);
id = obj.getId();  // Correct.
于 2010-06-12T09:15:23.910 回答