jQuery in Action, 2nd edition*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "cmp identity_insert" Watch "cmp identity_insert" New topic
Author

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"?>
<!DOCTYPE ejb-jar PUBLIC
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>Teste and Story</description>
<display-name>Teste and Story</display-name>
<enterprise-beans>
<entity>
<display-name>Department Entity CMP Bean</display-name>
<ejb-name>Department</ejb-name>
<unknown-pk>
<unknown-pk-class>java.lang.Integer</unknown-pk-class>
<column-name>depId</column-name>
<jdbc-type>INTEGER</jdbc-type>
<sql-type>int(4)</sql-type>
<auto-increment/>
</unknown-pk>
<entity-command name="key-generator" class="org.jboss.ejb.plugins.cmp.jdbc.keygen.JDBCKeyGeneratorCreateCommand"> <attribute name="key-generator-factory">UUIDKeyGeneratorFactory</attribute>
</entity-command>
<entity-command name="mssql-fetch-key"> <attribute name="pk-sql">SELECT @@IDENTITY</attribute>
</entity-command>
<home>masters.department.DepartmentHome</home>
<remote>masters.department.Department</remote>
<ejb-class>masters.department.DepartmentBean</ejb-class>
<reentrant>True</reentrant>
<persistence-type>Container</persistence-type>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>department</abstract-schema-name>
<primkey-field>DepId</primkey-field>
<prim-key-class>java.lang.Integer</prim-key-class>
<cmp-field><field-name>DepId</field-name></cmp-field>
<cmp-field><field-name>DepName</field-name></cmp-field>


</entity>

<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>
</enterprise-beans>


<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 >
<container-transaction>
<method>
<ejb-name>Story</ejb-name>
<method-name>*</method-name>
</method>

<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor >


</ejb-jar>

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

setDepName(DepName);

return null;
}

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cmp identity_insert