Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > auto-increment fields and xdoclet

Reply
Thread Tools

auto-increment fields and xdoclet

 
 
Tim
Guest
Posts: n/a
 
      11-22-2003
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


 
Reply With Quote
 
 
 
 
Tim
Guest
Posts: n/a
 
      11-22-2003
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
>
>



 
Reply With Quote
 
 
 
 
Sudsy
Guest
Posts: n/a
 
      11-22-2003
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!

 
Reply With Quote
 
Tim
Guest
Posts: n/a
 
      11-24-2003
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;


 
Reply With Quote
 
Tim
Guest
Posts: n/a
 
      11-24-2003
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Maven2 and XDoclet : org.xdoclet.plugin.web.TaglibPlugin don't generate TLD inherited attributes Greg Java 0 05-17-2006 07:37 AM
XDoclet and generating Dependent Value Classes Sigmund Lundgren Java 0 05-26-2004 07:58 PM
xdoclet facade and wrong packages for interfaces Kari Kangas Java 2 02-17-2004 07:28 AM
Problems with XDoclet and Value Object generation for CMR relationships Kenneth Aitken Java 0 01-28-2004 03:51 PM
maven and xdoclet steven Java 1 11-12-2003 03:59 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57