This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes cmp identity_insert Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "cmp identity_insert" Watch "cmp identity_insert" New topic

cmp identity_insert

alec stewart stewart
Ranch Hand

Joined: Dec 23, 2003
Posts: 71
hi all
i am using sqlserver 2000 and jboss 3.2.3
i have a table with identity column
table department
depid int (with identity)
depname varchar
the problem is that when i am trying to insert a a value in a table with identity through cmp i get the following error:
Cannot insert explicit value for identity column in table 'department' when IDENTITY_INSERT is set to OFF.

i even went to the database and did the IDENTITY_INSERT to off.

here is my ejb-jar.xml file

<?xml version="1.0" encoding="UTF-8"?>
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
<description>Teste and Story</description>
<display-name>Teste and Story</display-name>
<display-name>Department Entity CMP Bean</display-name>
<entity-command name="key-generator" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCKeyGeneratorCreateCommand"> <attribute name="key-generator-factory">UUIDKeyGeneratorFactory</attribute>
<entity-command name="mssql-fetch-key"> <attribute name="pk-sql">SELECT @@IDENTITY</attribute>


<resource-ref> <description>Default Database Connection</description><res-ref-name>jdbc/TestDS</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth> </resource-ref>

<entity-commands> <!-- define a command that uses an Oracle sequence to generate keys -->
<entity-command name="keygen" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCSQLServerCreateCommand"> </entity-command> </entity-commands>

<assembly-descriptor >

</assembly-descriptor >


and here are my create methods:
public Integer ejbCreate(String DepName) throws RemoteException, CreateException {
System.out.println("In ejbCreate()");


return null;

public void ejbPostCreate(String DepName) {
System.out.println("In ejbPostCreate()");

I agree. Here's the link:
subject: cmp identity_insert
It's not a secret anymore!