2 Replies Latest reply on Mar 28, 2006 10:42 PM by wargun02

    EJB3 Entity Primary Key Retrieval

    wargun02

      Hi,

      I have a problem with retrieving the primary key of an entity object after persisting. My case is:

      :- I have an entity object which has the id as the primary key field of type long and the value is auto generated by the database (and with all necessary annotations assigned)
      :- After I invoke the EntityManager "em" to persist my entity (e.g. em.persist(entityObj) ), I want to know what was the newly assigned primary key by the database.

      So, is there any way to retrieve the newly assigned primary key of the entity, since the EntityManager.persist() method returns nothing (void)?

      Any suggestion will be greatly appreciated. Thank you.


      Max Lam