2 Replies Latest reply on Sep 13, 2006 9:21 AM by wikijuarezjunior

    EJB 3.0 - PK Generation with GenerationType

    wikijuarezjunior

      Hi there,

      The types of primary key generation are defined by the GenerationType enum as shown below (from the ejb-3_0-fr-spec-persistence.pdf Final release):

      public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO };

      But as far as I understood there's no way to use user defined key strategy, i mean, what if I want to generate the keys myself?

      Please accept my apologies if there's another thread here regarding this issue but I've not been able to find it.

      Can't we use legacy databases with EJB 3.0??? Please could someone help?

      Thanks in advance!

      BR,

      Juarez Jr

        • 1. Re: EJB 3.0 - PK Generation with GenerationType
          ablevine1

          There is no way to do this that is ejb3-spec compliant, however, you can use some hibernate extensions to accomplish this.

          1. You need create an id genretor class that implements org.hibernate.id.IdentifierGenerator implementing the generate method to return your custom generated pk.

          2. Annotate the primary key getter method for you ejb with the following
          @Id
          @Column(name = "ID")
          @GeneratedValue(generator = "myCustomIDGen")
          @GenericGenerator(name = "myCustomIDGen", strategy = "full_classname_of_your_IdentifierGenerator_implementation")

          • 2. Re: EJB 3.0 - PK Generation with GenerationType
            wikijuarezjunior

            Hi ablevine1,

            Thanks a lot for you reply. I will check those Hibernate extensions and give them a try.

            BR,

            Juarez Jr