auto-increment fields and xdoclet

Discussion in 'Java' started by Tim, Nov 22, 2003.

  1. Tim

    Tim Guest

    I'm working on a CMP 2 entity bean and MS SQL Server 2000 and JBoss
    3.2.1/Tomcat 4.1.24.

    My primary key is an integer, auto-incremented by the database.

    I can't seem to get XDoclet v1.2b3 to generate the necessary items in
    jbosscmp-jdbc.xml to allow me to create a new record and have the database
    generate the key value. I am not trying to create it with an explicit
    value. It looks like the @jboss.unknown-pk is being completely ignored when
    generating the descriptor.

    Here's the JDBC error:
    "Cannot insert explicit value for identity column in table 'my_table' when
    IDENTITY_INSERT is set to OFF."

    Here are some XDoclet tags from my class-level comment:
    * @ejb.persistence table-name="gs_person"
    *
    * @jboss.persistence datasource="java:/MsSql2"
    * datasource-mapping="MS SQLSERVER2000"
    * table-name="my_table"
    * @jboss.unknown-pk class="java.lang.Integer"
    * column-name="my_id"
    * jdbc-type="INTEGER"
    * sql-type="int"
    * auto-increment="true"
    * @jboss.entity-command name="mssql-get-generated-keys"

    The entity-command exists in standardjbosscmp-jdbc.xml in my JBoss default
    conf dir.

    Any help is appreciated,
    Tim
    Tim, Nov 22, 2003
    #1
    1. Advertising

  2. Tim

    Tim Guest

    I tried to change all the references to my table name in my code sample to
    "my_table" but it looks like I missed one.

    Assume that all the table names actually match.

    Tim

    "Tim" <regtim@NOSPAM_shaw.ca> wrote in message
    news:qLyvb.454467$9l5.225912@pd7tw2no...
    > I'm working on a CMP 2 entity bean and MS SQL Server 2000 and JBoss
    > 3.2.1/Tomcat 4.1.24.
    >
    > My primary key is an integer, auto-incremented by the database.
    >
    > I can't seem to get XDoclet v1.2b3 to generate the necessary items in
    > jbosscmp-jdbc.xml to allow me to create a new record and have the database
    > generate the key value. I am not trying to create it with an explicit
    > value. It looks like the @jboss.unknown-pk is being completely ignored

    when
    > generating the descriptor.
    >
    > Here's the JDBC error:
    > "Cannot insert explicit value for identity column in table 'my_table' when
    > IDENTITY_INSERT is set to OFF."
    >
    > Here are some XDoclet tags from my class-level comment:
    > * @ejb.persistence table-name="gs_person"
    > *
    > * @jboss.persistence datasource="java:/MsSql2"
    > * datasource-mapping="MS SQLSERVER2000"
    > * table-name="my_table"
    > * @jboss.unknown-pk class="java.lang.Integer"
    > * column-name="my_id"
    > * jdbc-type="INTEGER"
    > * sql-type="int"
    > * auto-increment="true"
    > * @jboss.entity-command name="mssql-get-generated-keys"
    >
    > The entity-command exists in standardjbosscmp-jdbc.xml in my JBoss default
    > conf dir.
    >
    > Any help is appreciated,
    > Tim
    >
    >
    Tim, Nov 22, 2003
    #2
    1. Advertising

  3. Tim

    Sudsy Guest

    Tim wrote:
    > I'm working on a CMP 2 entity bean and MS SQL Server 2000 and JBoss
    > 3.2.1/Tomcat 4.1.24.
    >
    > My primary key is an integer, auto-incremented by the database.
    >

    <snip>
    > ...I am not trying to create it with an explicit value. ...

    <snip>

    That's what YOU say...

    > Here's the JDBC error:
    > "Cannot insert explicit value for identity column in table 'my_table' when
    > IDENTITY_INSERT is set to OFF."


    The error message indicates the opposite, namely that the insert is
    including a value for the field which has been specified as the
    identity column.
    Without seeing the code generated by the XDoclet, I'm stumped!
    Sudsy, Nov 22, 2003
    #3
  4. Tim

    Tim Guest

    I'm not sure how the Xdoclet code will help you, but a snippet is included
    below. At no point in my code do I pass it an id value.

    Here is the call I make to create the new record:

    PersonLocal newPerson = PersonUtil.getLocalHome().create("first", "middle",
    "last");

    Here is the create and post create from the bean implementation class:

    /**
    * Create a new person
    *
    * @ejb.create-method
    */
    public Integer ejbCreate (String lFirstName, String lMiddleName, String
    lLastName)
    throws CreateException {

    setFirstName(lFirstName);
    setMiddleName(lMiddleName);
    setLastName(lLastName);
    return null; //how do I actually get the new id?
    }

    /**
    * Code to run after ejbCreate() has completed
    */
    public void ejbPostCreate(String lFirstName, String lMiddleName, String
    lLastName) {
    }

    And here is the only relevant XDoclet generated code from the local home
    interface:

    public PersonLocal create(java.lang.String lFirstName, java.lang.String
    lMiddleName, java.lang.String lLastName)
    throws javax.ejb.CreateException;
    Tim, Nov 24, 2003
    #4
  5. Tim

    Tim Guest

    Found the problem!

    It was in my Ant build file.

    I changed the version on my <jboss> subtask of <ejbdoclet> from 3.0 to 3.2.

    Now it's all good.
    Tim, Nov 24, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg
    Replies:
    0
    Views:
    618
  2. Replies:
    104
    Views:
    10,937
    Jordan Abel
    Oct 28, 2005
  3. Replies:
    99
    Views:
    2,479
    eliza81
    Jun 11, 2010
  4. Alf P. Steinbach /Usenet
    Replies:
    0
    Views:
    880
    Alf P. Steinbach /Usenet
    May 22, 2011
  5. Peng Yu

    post increment or pre increment?

    Peng Yu, Nov 21, 2008, in forum: Perl Misc
    Replies:
    7
    Views:
    508
    Peter J. Holzer
    Nov 23, 2008
Loading...

Share This Page