1 Reply Latest reply on Sep 20, 2002 7:27 PM by Dain Sundstrom

    CMP, auto-increment, and MySQL

    Andrea Newbie

      The "EJB Design Patterns" book, by Floyd Marinescu, states that autoincrement cannot be done when using CMP. It seems that this is no longer the case.

      According to the MySQL website, this can be done with the new beta version of Connector/J. See http://www.mysql.com/products/connector-j/index.html.

      The question is, how to use the MySQL AUTO_INCREMENT with CMP?

      Specifically, how does one retrieve the auto-generated id number when creating the ejb object, in ejbCreate or ejbPostCreate, so that the entity data object can be updated?

      Also, is it possible to use xdoclet to specify that a pk-field is autoincremented, so that JBoss can create the table?

      I hear that support for autoincrement was commented out of JBoss recently, due to a build problem. So it seems that we will need to wait a bit until autoincrement is back ported to JBoss 3.2 (?).

      I believe this is an exciting new feature, preferrable to coding a primary key generation strategy, although perhaps a bit more RDBMS specific.

      Anyone share my bloodlust for the cutting edge? Please share what you know about how to implement autoincrement using JBoss, CMP, and MySQL.

      Thanks in advance!

      Andrea

        • 1. Re: CMP, auto-increment, and MySQL
          Dain Sundstrom Master

          > The "EJB Design Patterns" book, by Floyd Marinescu,
          > states that autoincrement cannot be done when using
          > CMP. It seems that this is no longer the case.

          Floyd is not the brightest bulb.

          > According to the MySQL website, this can be done with
          > the new beta version of Connector/J. See
          > http://www.mysql.com/products/connector-j/index.htm
          >
          .
          >
          > The question is, how to use the MySQL AUTO_INCREMENT
          > with CMP?

          Is is done by the container. This is in CVS HEAD (JBoss 4.0)

          > Specifically, how does one retrieve the
          > auto-generated id number when creating the ejb
          > object, in ejbCreate or ejbPostCreate, so that the
          > entity data object can be updated?

          You can't, but the container can.

          > Also, is it possible to use xdoclet to specify that a
          > pk-field is autoincremented, so that JBoss can create
          > the table?

          Not yet. I think it is in the works. XDoclet is always a little behind, because it is currently maintained at the XDoclet site.

          > I hear that support for autoincrement was commented
          > out of JBoss recently, due to a build problem. So it
          > seems that we will need to wait a bit until
          > autoincrement is back ported to JBoss 3.2 (?).

          Alex is working on it right now.

          > I believe this is an exciting new feature,
          > preferrable to coding a primary key generation
          > strategy, although perhaps a bit more RDBMS
          > specific.

          I agree.

          > Anyone share my bloodlust for the cutting edge?
          > Please share what you know about how to implement
          > autoincrement using JBoss, CMP, and MySQL.

          I do. I can't wait to try it with the Forums on JBoss project. You should read this post:

          http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/