I hope this is not a FAQ and that it's OK to ask JPA questions on this forum. I'm using JBoss with JPA and Hibernate.....
With Hibernate, I am able to retrieve the generated ID of a newly saved object via:
Serializable id = Session.save(newObject);
However, switching to JPA this is not an option since persist() does not return the new ID.
newObject.getId() is null after the call to persist(). I have also followed up with a call to flush() but this does not make a difference.
I have also tried using Hibernate save():
Serializable id = ((Session)em.getDelegate()).save(newObject)
where "em" is the JPA entity manager. This does not return a value either.
Have I missed something obvious? How can one obtain the ID of a newly persisted entity using JPA?
Thanks!
|