1 Reply Latest reply on Oct 9, 2002 1:48 PM by Alexey Loubyansky

    How to get new inseted autogeneated primary key?

    Adis Newbie

      I wonder if there is some nice way to get new inserted auto generated primary key with SQL Server 2000.
      I use microsoft jdbc driver.
      The point is I have one BMP Bean and when I run insert in ejbCreate I would like to return back autogenerated key.
      I need some nice way.
      I could of course run select statement with some of information that I inserted but there may be some better way. So please if you know this just write couple of rows to explain how to do this.


        • 1. Re: How to get new inseted autogeneated primary key?
          Alexey Loubyansky Master

          For CMP beans see the thread NEW FEATURE: new ways to create entity beans.

          For BMP, I am not sure about a nice way to do it. You should learn the api of the driver you use and you'll face many problems.
          I would recommend you to use key generator. UUIDKeyGenerator is available in JBoss since 3.2 version. It generates 32 bit length uuid's. You can use it or implement your own key generator.