This content has been marked as final. Show 2 replies
I had the same question before.
Supposing the method entityObj.getId() returns the value or field annotated as @Id, what you can do is the following:
MyEntity entityObj = new MyEntity(...); em.persist(entityObj); long assignedPrimaryKey = entityObj.getId();
This is a cool solution, it worked! Tested and verified. Thanks again.