Getting the PK in ejbPostCreate()


EJB programming & troubleshooting: Getting the PK in ejbPostCreate()

  1. Getting the PK in ejbPostCreate() (1 messages)

    i'm using a ejbCreate() in a auto_increment table, so, i don't pass the pk as a parameter in ejbCreate().

    Though, i need to get it after the insertion, in ejbPostCreate(). What is the best way to do that?

    For example, in a Person CMP i'd have.

    public java.lang.Integer ejbCrate(String name) throws...

    //i need now to recover the Person ID, wich is
    //auto_incremten field

    public void ejbPostCreate(String name) throws...
        setPersonID( GET THE PERSON ID FROM THE DB );

  2. You should be able to get this value via the EntityContext.getPrimaryKey() method.