1 Reply Latest reply on May 23, 2006 6:09 PM by Shane Bryzak

    Value of auto-increment field not updated?

    Remco Jansen Newbie

      We're working on a Seam application for an educational project and are experiencing problems when dealing with (what I would call) "just-created instances".

      When we ask for the value of the primary key of an instance that has just been created (in other words: that has NOT been retrieved from or stored to the database), it's value is always 0.

      This primary key though, is an auto-increment field in the MySQL database. While the value of this field in the persistence context is 0, the value is stored correctly in the database (i.e. not 0).

      I thought it might be good to update the instance manually with the new data, but since the value of the identifying field of the instance is 0, a call to entityManager.refresh(instance) results in an EntityNotFoundException.

      Unfortunately, the wrong value in the persistence context raises a problem while trying to add another instance of the same type. Then the application will try to figure out if an instance with the identifier of the instance to be added already exists and reports positively of course. This makes it impossible to add a second instance w/o returning to the main screen of the application and starting over again.

      After reading through many topics on this forum, I began to think that it might have something to do with the mysql-get-generated-keys entity-command of Hibernate, but I can't figure out what the Seam-equivalent of this setting would be or whether this is relevant at all when Seam is being used....

      The application is based upon a framework generated by the reverse engineering tool. We're using Jboss 4.0.4RC1. We've tried Seam 1.0 beta 2 as well as Seam 1.0.0 CR2.

      I hope that someone can make things a bit more clear for me or perhaps point me to some place where I can find more information on this particular subject.

      Thanks much in advance!

      Cheers, Remco