auto-increment fields and xdoclet

T

Tim

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
 
T

Tim

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
 
S

Sudsy

Tim said:
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 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!
 
T

Tim

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;
 
T

Tim

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top