1 Reply Latest reply on May 22, 2008 6:19 PM by infinity2heaven

    EJB3 Persistence - how to read back assigned primary key

    Dowell Griffin Newbie

      This should be simple. I need to understand what I am missing. I cannot read back the primary key (pk)after calling persist.  I can see the row in the DB with the primary key that was auto-assigned by MySql.

      JBoss AS 4.0.5  w/EJB3
      Seam 1.2.1   w/conversation scoped entitymanager
      MySQL 5.1
      Hibernate 3.2.5


                  int pk = theEntity.getPk()
      (what the heck: I has to escape the equal sign above or the text is rejected in the topic editor)

      Tried refresh(theEntity) which fails with an EntityNotFoundException (presumably because its pk is zero and refresh needs to know the pk).

      Of note.  It looks like the row is not actually flushed to the DB when flush is called.  It looks like it occurs when the control is returned to the view meaning the entire call stack started by the action exits.