Discussions

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

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

    Hi,
    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.

    [code]
    public java.lang.Integer ejbCrate(String name) throws...
    {
       setName(name);
    }

    //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 );
    }
    [/code]

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