问题
I am using datanucleus and jdo in a GWT project. How can I retrieve the generated primary key after adding an element to the database with makePersistent()
Edit We use annotations, here is the primary key:
@PrimaryKey
@Column(name = "id_bla", allowsNull = "false")
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY, extensions = { @Extension(vendorName = "datanucleus", key = "strategy-when-notnull", value = "false") })
private Long idBla;
I am not the one who did the mapping and I don't get all of this yet.
回答1:
The object's key should be automatically set when it is persisted:
MyObject obj = new MyObject();
Long id = obj.getId(); // WRONG! Will still be null.
pm.makePersistent(obj);
id = obj.getId(); // Correct.
来源:https://stackoverflow.com/questions/3021297/datanucleus-jdo-retrieve-newly-generated-primary-key