0 Replies Latest reply on May 5, 2005 12:35 PM by robr

    How do you use an entity bean that uses a identiy column for

    robr

      I am using an mssql database. I need to create an entity bean for a table that uses an identity column. I want to use the identity column as the Primary key in the entity bean.

      I assumed that I should not pass in a paramter for the identity column into the create method of the Home interface or the create method of the Bean ejbCreate method. But when I try using the entitity bean to create a new row in the table I get the following error.

      Cannot insert explicit value for identity column in table 'PropsTableIdentity when IDENTITY_INSERTis set to OFF.

      I didn't think I was doing anything to explicitly insert anything into the identity column.

      Anyways here are my programs if anybody cares to take a look.

      PropsIdentity.java

      package propsIdentity;
      // File generated by Desiderata Software's Blazix entity bean wizard
      // Thu May 05 08:20:44 MDT 2005
      
      // Remote interface for entity bean "PropsIdentity"
      
      
      import javax.ejb.*;
      import java.rmi.*;
      
      public interface PropsIdentity extends javax.ejb.EJBObject {
       int getKey() throws java.rmi.RemoteException;
       java.lang.String getValue() throws java.rmi.RemoteException;
       void setValue( java.lang.String value ) throws java.rmi.RemoteException;
       // TBD: Add any additional remote method interfaces
       //
      
      }
      



      PropsIdentityHome.java
      package propsIdentity;
      // File generated by Desiderata Software's Blazix entity bean wizard
      // Thu May 05 08:20:44 MDT 2005
      
      // Home interface for entity bean "PropsIdentity"
      
      
      import javax.ejb.*;
      import java.rmi.*;
      import java.util.*;
      
      public interface PropsIdentityHome extends javax.ejb.EJBHome {
       PropsIdentity create(
       java.lang.String value
       ) throws javax.ejb.CreateException, java.rmi.RemoteException;
      
       PropsIdentity findByPrimaryKey( java.lang.Integer pkey ) throws javax.ejb.FinderException, java.rmi.RemoteException;
      
      
      }
      



      PropsIdentityBean.java
      // Thu May 05 08:20:44 MDT 2005
      
      // Bean class for entity bean "PropsIdentity"
      
      
      import javax.ejb.*;
      import javax.naming.*;
      import java.rmi.*;
      
      public class PropsIdentityBean implements javax.ejb.EntityBean {
      
       //Instance member variables.
       //
       public int key = 0;
       public java.lang.String value = null;
      
       // Entity context, can be used to obtain handles etc
       //
      
       javax.ejb.EntityContext ejbEntityContext = null;
      
       //Getter/setter methods
       //
      
       public int getKey() throws java.rmi.RemoteException
       {
       return key;
       }
      
       public java.lang.String getValue() throws java.rmi.RemoteException
       {
       return value;
       }
      
       public void setValue( java.lang.String value ) throws java.rmi.RemoteException
       {
       this.value = value;
       }
      
       // TBD: Add implementations for any additional remote method interfaces
       //
      
       // The default ejbCreate method.
       //
      
       public java.lang.Integer ejbCreate(
       java.lang.String value
       )
       throws javax.ejb.CreateException, java.rmi.RemoteException
       {
       this.value = value;
       return null;
       }
      
       // TBD: If any other ejbCreate's are added manually to the home interface, define them.
       //
      
       // Other methods required in an entity bean
       //
      
       public void setEntityContext( javax.ejb.EntityContext ejbEntityContext )
       throws RemoteException
       {
       this.ejbEntityContext = ejbEntityContext;
       }
      
       public void unsetEntityContext()
       throws RemoteException
       {
       this.ejbEntityContext = null;
       }
      
       public void ejbPostCreate(
       java.lang.String value
       )
       {
       // TBD: Do any post-instance-creation processing here
       }
      
       public void ejbRemove()
       throws java.rmi.RemoteException, javax.ejb.RemoveException
       {
       // TBD: Do any processing here when instance is being removed
       }
      
       public void ejbActivate()
       throws java.rmi.RemoteException
       {
       // TBD: Do any processing here when instance is activated
       }
      
       public void ejbPassivate()
       throws java.rmi.RemoteException
       {
       // TBD: Do any processing here when instance is being passivated
       }
      
       public void ejbLoad()
       throws java.rmi.RemoteException
       {
       // TBD: Load any data needed by instance
       // in addition to the container-managed data.
       }
      
       public void ejbStore()
       throws java.rmi.RemoteException
       {
       // TBD: Store any data used by instance
       // in addition to the container-managed data.
       }
      
      }
      


      Script used to create table in mssql

      if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PropsTableIdentity]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
      drop table [dbo].[PropsTableIdentity]
      GO
      
      CREATE TABLE [dbo].[PropsTableIdentity] (
       [key] [int] IDENTITY (1, 1) NOT NULL ,
       [value] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
      ) ON [PRIMARY]
      GO
      
      


      Anybody have any clue on how to figure the entity bean to work with the identity column?