4 Replies Latest reply on Apr 14, 2002 10:40 AM by yumariso

    Compound / auto generated  primary key

    dencel

      Hello everybody,
      I have two questions about configuring CMP-entity keys.

      First: Is it possible to create a primary key made of more then one (multiple) database-fields / entity-attributes?. If so, how do I create the entityHome and entityEJB and what do I tell the ejb-jar?

      Second: The second question is about auto-generated primary keys from the database-server. I get this huge null-pointer exceptions in Jboss trying to use them. Although I know a autogenerated keys (int) is not how it should be in design-technical ways, it was already implemented in the database. Which attributes and methods are needed in entityEJB, and what should I tell the ejb-jar?

      I hope someone can help me, I'm struggling with these problems for several days now.

      Thanx,
      Dencel

        • 1. Re: Compound / auto generated  primary key
          dsundstrom

          > First: Is it possible to create a primary key made of
          > more then one (multiple) database-fields /
          > entity-attributes?. If so, how do I create the
          > entityHome and entityEJB and what do I tell the
          > ejb-jar?

          Yes you can. I suggest you read the EJB 2.0 spec, or one of the books on EJB. You can get a free copy of Mastering EJB at http://www.theserverside.com

          > Second: The second question is about auto-generated
          > primary keys from the database-server. I get this
          > huge null-pointer exceptions in Jboss trying to use
          > them. Although I know a autogenerated keys (int) is
          > not how it should be in design-technical ways, it was
          > already implemented in the database. Which attributes
          > and methods are needed in entityEJB, and what should
          > I tell the ejb-jar?

          Auto-generated keys are not supported by JBoss. Sometime after JavaOne I'll be adding support for (JBoss) server auto-generated primary keys to JBossCMP, but this won't help you because you are using database generated primary keys. Eventually I'll add support for database generated primary keys, but this depends on some vendors releasing drivers that support JDBC 3.0, which and handle database generated column values on insert and update.

          • 2. Re: Compound / auto generated  primary key
            dencel

            Thank you for the reaction. I will read the documentation, I failed to see it was a standard EJB issue.
            The answer on the second question surprises me because, although wrong by principals, an auto generated key is a very common thing in the world of databases.
            Now it's up to the EJBimpl logic to determine an available integer in the database and assign it as primary key, when you enumerate your customers for example..
            But I quess I have to live with that for a while. Thanks again,
            Dencel

            • 3. Re: Compound / auto generated  primary key
              dsundstrom

              > The answer on the second question surprises me
              > because, although wrong by principals, an auto
              > generated key is a very common thing in the world of
              > databases.

              I have always liked db auto-generated PKs, but until JDBC 3.0 was released there was no generic way to use them. I hope the drivers come out faster then the JDBC 2.0 drivers.

              • 4. Re: Compound / auto generated  primary key
                yumariso

                I suppose this will cause problems with any auto-generated fields in tables?

                Isn't there a way to specify in jaws configuration not to set or update certain fields?