0 Replies Latest reply on Jul 10, 2005 10:18 PM by zorzella

    Why can't I set my PK in a @PrePersist method?

    zorzella

      I have an Entity Bean that uses a GUID generator for setting its PKs (rather than a sequence). I have it working by setting the GUID in the constructor, but I want to avoid that, so I tried writting a @PrePersist method (see below) that sets my PK. Now, even though the docs say @PrePersist is called before a SQL CREATE, JBoss (4.0.3RC1) is throwing an exception with the message "ids for this class must be manually assigned before calling save()".

      BTW, if I set the GUID in the constructor (which, again, I want to avoid) and place some other stuff in the @PrePersist method, it does get called before the DB INSERT happens.

      Any clues? The method is presented below.

      Zorzella

      *******************

      @PrePersist
      public void prePersist () {
      setGuid(Guid.generateGUID(this));
      }