Question

I'm trying to persist a new Java object which has an auto-generated Id but it is not being populated upon calling EntityManager's persist() method. I have in my Object class..

...
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
...

and I'm persisting it essentially using...

emf = Persistence.createEntityManagerFactory("transactions-optional");
em = emf.createEntityManager();
em.persist(myObj);

After persisting it, the id field is not populated. I've tried calling em.flush() but it complains that it must be inside a transaction. I don't need or want transactions but I do need this Id immediately after persisting the object.

Is this a bug in GAE's implementation of JPA?

Any suggestions would be much appreciated!

Was it helpful?

Solution

I can confirm that calling em.refresh(object) will populate the id of the persisted object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top